|
I've been staring at the same sections of code for two hours... |
Jason Marmon
Member #14,859
January 2013
|
I'm making a game right now. I'm laying down the framework currently, and I am having the most annoying issue: for some reason, I get an error when I try to draw text in my class file. It tells me that there's an assertion error. Here's the class file instance of the function: 1void playerQuit() // if player hits esc, give exit menu, else do nothing
2{
3 al_set_new_display_flags(ALLEGRO_FULLSCREEN);
4 ALLEGRO_FONT* font=al_load_ttf_font("font.ttf", 20, 0);
5 ALLEGRO_KEYBOARD_STATE kstate;
6 al_get_keyboard_state(&kstate);
7 if(al_key_down(&kstate, ALLEGRO_KEY_ESCAPE))
8 {
9 while (1)
10 {
11 al_clear_to_color(al_map_rgb(NULL,NULL,NULL));
12 al_draw_text(font, al_map_rgb(0,250,250), 1200, 400, 0, "Are you sure you want to quit? Press \"y\" or \"n\"");
13 al_flip_display();
14 al_get_keyboard_state(&kstate);
15 if (al_key_down(&kstate, ALLEGRO_KEY_Y))
16 exit (0);
17 else if (al_key_down(&kstate, ALLEGRO_KEY_N))
18 break;
19 }
20 }
21}
this is the header information in both the main and class file: #pragma once #include <allegro5\allegro.h> #include<allegro5\allegro_image.h> #include<allegro5\allegro_audio.h> #include<allegro5\allegro_acodec.h> #include<allegro5\allegro_font.h> #include <allegro5\allegro_ttf.h> #include<allegro5\allegro_native_dialog.h> #include <ctime> #include "functions.h" in case you wanted to see the entire main function, here it is too: 1#pragma once
2#include <allegro5\allegro.h>
3#include<allegro5\allegro_image.h>
4#include<allegro5\allegro_audio.h>
5#include<allegro5\allegro_acodec.h>
6#include<allegro5\allegro_font.h>
7#include <allegro5\allegro_ttf.h>
8#include<allegro5\allegro_native_dialog.h>
9#include <ctime>
10#include "functions.h"
11class droppers
12{
13public:
14 float x[50];
15 float y[50];
16 ALLEGRO_BITMAP* DROPPER_BITMAP;
17}L1_DROPPER, L2_DROPPER;
18int main(){
19 al_init();
20 al_init_image_addon();
21 al_init_font_addon();
22 al_init_ttf_addon();
23 al_install_audio();
24 al_install_keyboard();
25 al_set_new_display_flags(ALLEGRO_FULLSCREEN);
26 ALLEGRO_DISPLAY *display = NULL;
27 ALLEGRO_DISPLAY_MODE disp_data;
28 ALLEGRO_KEYBOARD_STATE kstate;
29 ALLEGRO_FONT* font =al_load_font("font.TTF", 20, 0);
30 ALLEGRO_BITMAP*dot=al_load_bitmap("white_dot.png");
31 al_get_display_mode(al_get_num_display_modes() - 1, &disp_data); // these two lines
32 display = al_create_display(disp_data.width, disp_data.height);//set display mode based on user's current resolution
33 al_hide_mouse_cursor(display);
34// ALLEGRO_TIMER* timer;
35 bool mainProgramDone=false;
36 while (!mainProgramDone)
37 {
38 float x=700;
39 float y=700;
40 bool done=false;
41 bool quit;
42 while(!done)
43 {
44 al_get_keyboard_state(&kstate);
45 //****************MOVEMENT****************
46 if((al_key_down(&kstate, ALLEGRO_KEY_LEFT)||al_key_down(&kstate, ALLEGRO_KEY_A))&&XLeftBound(x))//this section moves player
47 x-=1;
48 if((al_key_down(&kstate, ALLEGRO_KEY_RIGHT)||al_key_down(&kstate, ALLEGRO_KEY_D))&&XRightBound(x)) //as long as he/she is within bounds of map
49 x+=1.5;
50 //****************end of movement section***************
51 playerQuit();
52 //***********DRAWING****************
53 al_clear_to_color(al_map_rgb(0,0,0));
54 //put all drawing text between
55 al_draw_bitmap(dot, x, y, NULL);
56 //these two comments (to ensure the screen gets cleared and that the new drawing is part of the update)
57 al_flip_display();
58 //************END DRAWING*********
59 }
60 }
61 return 0;
62}
if you need to see anything else (i.e. another function), let me know. thanks in advance! P.S.: Some of it may be confusing because it's set up for later in the game development process (e.g. the array of x values for droppers). Hope it doesn't confuse you too much |
Kris Asick
Member #1,424
July 2001
|
One thing right off the bat: You need to set your display mode BEFORE you load any bitmaps or fonts. See if that fixes the problem. --- Kris Asick (Gemini) |
Jason Marmon
Member #14,859
January 2013
|
didn't do anything =/ |
SiegeLord
Member #7,827
October 2006
|
Why are you calling al_set_new_display_flags in playerQuit? Why are you loading the font every single time in that function without destroying it (this is your error btw)? Also... I object to you using keyboard state like that (you really should be using events)... and even if you do use keyboard state, then don't mix drawing and logic like that. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Jason Marmon
Member #14,859
January 2013
|
I set the flags to see if I could fix it (prior to your response, I thought there might have been an issue with the display not being part of the current thread). Thanks so much for the help, I fixed it now. Also, I'm not sure what you mean by events, but I'll read up on them now. Could you explain what you mean by mixing drawing and logic though? |
|