|
in game messagebox ? |
imgregduh
Member #15,241
July 2013
|
I created a dialog class that will be called in what I call a player class which has all the inputs but I'm having an issue having the dialog draw to the screen when I hit spacebar. EDIT: 1#pragma once
2#include"GameObject.h"
3
4class Dialog : GameObject
5{
6private:
7 ALLEGRO_FONT *font10;
8 ALLEGRO_FONT *font12;
9 ALLEGRO_FONT *font18;
10 ALLEGRO_FONT *font20;
11 ALLEGRO_FONT *font24;
12 ALLEGRO_FONT *font36;
13 int TextOffSet;
14public:
15 friend class Player;
16 Dialog();
17 ~Dialog();
18 void DrawDialogBox();
19 void CreateDialogBox(int size/*10,12,18,20,24,36*/, string message);
20
21};
1#include"Dialog.h"
2Dialog::Dialog()
3{
4 TextOffSet = 10;
5 font10 = al_load_font("FONT/arial.ttf", 10, 0);
6 font12 = al_load_font("FONT/arial.ttf", 12, 0);
7 font18 = al_load_font("FONT/arial.ttf", 18, 0);
8 font20 = al_load_font("FONT/arial.ttf", 20, 0);
9 font24 = al_load_font("FONT/arial.ttf", 24, 0);
10 font36 = al_load_font("FONT/arial.ttf", 36, 0);
11}
12Dialog::~Dialog()
13{
14 al_destroy_font(font10);
15 al_destroy_font(font12);
16 al_destroy_font(font18);
17 al_destroy_font(font20);
18 al_destroy_font(font24);
19 al_destroy_font(font36);
20
21}
22
23void Dialog::DrawDialogBox()
24{
25 al_draw_filled_rounded_rectangle(TextOffSet,HEIGHT -HEIGHT/4,WIDTH-TextOffSet,HEIGHT-TextOffSet,5,5,al_map_rgb(0,0,255));
26 al_draw_rounded_rectangle(TextOffSet,HEIGHT -HEIGHT/4,WIDTH-TextOffSet,HEIGHT-TextOffSet,5,5,al_map_rgb(255,255,255),TextOffSet);
27}
28
29void Dialog::CreateDialogBox(int size/*10,12,18,20,24,36*/, string message)
30{
31 DrawDialogBox();
32 switch(size)
33 {
34 case 10:
35 al_draw_text(font10,al_map_rgb(255,255,255),TextOffSet*2,(HEIGHT - HEIGHT/4)+TextOffSet,ALLEGRO_ALIGN_LEFT,message.c_str());
36 break;
37 case 12:
38 al_draw_text(font12,al_map_rgb(255,255,255),TextOffSet*2,(HEIGHT - HEIGHT/4)+TextOffSet,ALLEGRO_ALIGN_LEFT,message.c_str());
39 break;
40 case 18:
41 al_draw_text(font18,al_map_rgb(255,255,255),TextOffSet*2,(HEIGHT - HEIGHT/4)+TextOffSet,ALLEGRO_ALIGN_LEFT,message.c_str());
42 break;
43 case 20:
44 al_draw_text(font20,al_map_rgb(255,255,255),TextOffSet*2,(HEIGHT - HEIGHT/4)+TextOffSet,ALLEGRO_ALIGN_LEFT,message.c_str());
45 break;
46 case 24:
47 al_draw_text(font24,al_map_rgb(255,255,255),TextOffSet*2,(HEIGHT - HEIGHT/4)+TextOffSet,ALLEGRO_ALIGN_LEFT,message.c_str());
48 break;
49 case 36:
50 al_draw_text(font36,al_map_rgb(255,255,255),TextOffSet*2,(HEIGHT - HEIGHT/4)+TextOffSet,ALLEGRO_ALIGN_LEFT,message.c_str());
51 break;
52 }
53}
1void Player::PlayerInputDown( int keycode)
2{
3 Dialog dialog;
4 if(!GetAwake())
5 {
6 switch(keycode)
7 {
8 case ALLEGRO_KEY_ESCAPE:
9 SetEnd(true);
10 break;
11 case ALLEGRO_KEY_LEFT:
12 keys[LEFT] = true;
13 SetAwake(true);
14 break;
15 case ALLEGRO_KEY_RIGHT:
16 keys[RIGHT] = true;
17 SetAwake(true);
18 break;
19 case ALLEGRO_KEY_UP:
20 keys[UP] = true;
21 SetAwake(true);
22 break;
23 case ALLEGRO_KEY_DOWN:
24 keys[DOWN] = true;
25 SetAwake(true);
26 break;
27 case ALLEGRO_KEY_SPACE:
28 keys[SPACE] = true;
29 SetAwake(true);
30 dialog.CreateDialogBox(10,"something something something");
31 break;
32 }
33 }
34 SetAwake(true);
35}
36
37void Player::PlayerInputUp( int keycode)
38{
39 switch(keycode)
40 {
41 case ALLEGRO_KEY_ESCAPE:
42 SetEnd(true);
43 break;
44 case ALLEGRO_KEY_LEFT:
45 if(keys[LEFT])
46 {
47 keys[LEFT] = false;
48 SetAwake(false);
49 }
50 break;
51 case ALLEGRO_KEY_RIGHT:
52 if(keys[RIGHT])
53 {
54 keys[RIGHT] = false;
55 SetAwake(false);
56 }
57 break;
58 case ALLEGRO_KEY_UP:
59 if(keys[UP])
60 {
61 keys[UP] = false;
62 SetAwake(false);
63 }
64 break;
65 case ALLEGRO_KEY_DOWN:
66 if(keys[DOWN])
67 {
68 keys[DOWN] = false;
69 SetAwake(false);
70 }
71 break;
72 case ALLEGRO_KEY_SPACE:
73 keys[SPACE] = false;
74 SetAwake(false);
75 break;
76 }
77}
|
AmnesiA
Member #15,195
June 2013
|
Could you post the code that draws to the screen (where you flip display/tell the dialog box to draw)? ======================= |
J-Gamer
Member #12,491
January 2011
|
imgregduh said: case ALLEGRO_KEY_SPACE: keys[SPACE] = true; SetAwake(true); dialog.CreateDialogBox(10,"something something something"); al_flip_display(); break; You immediately draw your dialog box and flip the display. You shouldn't be doing any drawing in your logic code. " There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo |
imgregduh
Member #15,241
July 2013
|
<quote name="J-Gamer"//">You immediately draw your dialog box and flip the display. You shouldn't be doing any drawing in your logic code.</quote> How would I create a dialog box triggered by pressing a button then ? |
beoran
Member #12,636
March 2011
|
Let the button press toggle or set some variable somewhere. Then on drawing, check that variable and draw the dialog if the variable is set, and don't when it's not set. You can wrap this all in your dialog class though separate on_button and on_draw methods. Hope that helps... |
imgregduh
Member #15,241
July 2013
|
beoran said: Let the button press toggle or set some variable somewhere. Then on drawing, check that variable and draw the dialog if the variable is set, and don't when it's not set. You can wrap this all in your dialog class though separate on_button and on_draw methods. Hope that helps... I think my post is a bit misleading. I only put that there to see if it will draw, I dont plan on leaving it there like that. Its not drawing the dialog box at all but when I use the function in the main function it draws the dialog box but not inside that class for some reason but! I think that may be the issue, that i need to toggle the function |
|