c++ - in SDL when i draw a menu over the screen it makes the game slower and doesn't work how can i fix this? -
hi i've been coding on sdl couple of months, i'm makin little game try, can manage states, have intro screen main screen play button , game state,i load map , drow characters(entities) 1 control , make collision test, can make camera focus on character , follow him arroun map, problem want try in game menus(to give more speed,health,strenght character , things that) made new class tha renders menu on screen image covers whole screen , button closes menu, when activate menu (whit key down event) menu shows button doesn't , after while menu doesn't show anymore , event "creates menu" doesn't work.
my code drawing on screen this:
bool draw::ondraw(sdl_surface* screen, sdl_surface* image_draw, int x, int y) { if(screen == null || image_draw == null) { return false; } sdl_rect drawing; drawing.x = x; drawing.y = y; sdl_blitsurface(screen, null, image_draw, &drawing); return true; }
also create screen this:
if((screen = sdl_setvideomode(640, 480, 32, sdl_hwsurface | sdl_doublebuf)) == null) { return false; }
i've tried sdl_flip(screen) nothing, think problem draw on screen other way use make menu. more code:
i'm activating menu this:
case sdlk_h: { hero_menu = true; break; }
on render function this:
if(hero_menu) { menuhero call_menu; call_menu.activate_menu(screen); } void menuhero::activate_menu(sdl_surface* screen) { menu_back = draw::onload("./image/hero_screen.png"); close_button = draw::onload("./image/close.png"); draw::ondraw(screen, menu_back, 0, 0);
edit: 11/7/03 found error, , able resolve it, have new problem now, i'm calling menu this:
case sdlk_h: { menuhero activate; activate.activate_menu(); break; }
and in activate_menu() function menuhero class have this:
void menuhero::activate_menu() { sdl_surface* screen; menu_back = draw::onload("./image/hero_screen.png"); draw::ondraw(screen, menu_back, 0, 0);
now doesn't draw screen, i've been using sdl_surface* screen in whole code. not pointing screen? or screen in scope empty? how can solve this?
how slow "slow"? didn't specify numbers, if it's just drop in fps, can ignored. many people freak out when speed drops few hundred (!) fps, not realizing that measurement small amount.
how loading images? make sure convert them optimized format displaying. if don't convert them when they're loaded, every single blit sdl have manually convert every single pixel, , can cause real slowdowns.
(note: first article linked 1 wrote , posted on gamedev.net. i'm not aware of similar resources link people on subject, , don't benefit (financial or otherwise) linking it. second linked wasn't written me 1 i've found useful , helpful in past)
edit:
ah, there's real slowdown (now original question editted). you're accidentally (?) reloading menu images harddrive every time want draw menu. that's big slowdown, because accessing harddrive 1 of slowest things computers do!
or, @ least that's looks like doing. you're posting tiny tiny snippets of code project, , it's not enough know sure. programs complicated things have different parts of code interact in intricate ways, you're asking guess word spelling, hiding 90% of letters in it. it's hard debug , play hangman @ same time! =)
we need see intricate whole of related parts solve problem. these kinds of questions better suited community forums q&a sites, imo.
edit 2: new problem if declare new "sdl_surface *screen" local function, that's entirely different pointer other variables happen named "screen" elsewhere in code.
Comments
Post a Comment