first game problems

Started by
3 comments, last by Shuger 18 years, 7 months ago
Hi everyone, Few days ago i've started coding my first game. Basicly this is a game where you can fly spaceship over planet and your quest is to land. It's in early alpha state for now so it's extremely bugged. The problem is that some of these bugs i cannot fix no matter how hard i try. i hope you can help me. First of all: whole background blinks, i'm using SDL. The funny thing is that if i fly over background it turns normal and stays in that state. I could redraw background in each loop but it's extremely slow, i hope someone can help me with that. Second of all: is there a function in SDL which allows to rotate images? i'm curious becouse i wanted to save some memory. Third of all: I written a function which should count fps(i need it for performance tests) but it don't work i was trying to figure it out for about hour; still it don't work properly maybe you will know why, here it is: float fps() { float time,time2,timediff,frames; time = SDL_GetTicks(); timediff = time - time2; frames = 1000\timediff; time2 = time; } and the last one how to load and display multiple images from one surface? i've tried using an array as surface name(for example: SDL_Surface *image[2])but it don't work thanks
Advertisement
1. About blinking - it's too hard to say what causes it without seeing a line of code. Don't know, are you using SDL_Flip() or SDL_UpdateRectangle()? Is your application using double buffering / dirty rectangles or what? Is it fullscreen / windowed application?

2. There aren't any functions for rotation in SDL, and you shouldn't expect them. There are things like SDL_Rotozoom out there, but in reality I would suggest to use OpenGL instead.

3. Timing - you have uninitialized variable (time2) - maybe it's causing problems?

4. And on the last one, you will have to elaborate a little more - what does it mean to display multiple images from one surface? IMHO, this can be done through blitting - read on SDL Wiki about SDL_BlitSurface.
Quote:Original post by Shuger
float fps()
{
float time,time2,timediff,frames;
time = SDL_GetTicks();
timediff = time - time2;
frames = 1000\timediff;
time2 = time;
}


Everytime the function is called time2 is reset. Move the declaration of time2 out of the function or make it static and it should work
As already pointed out that fps counter problem is probarly due to an uninitialized variable.

float fps()
{
float time,time2,timediff,frames;
time = SDL_GetTicks();
timediff = time - time2;
frames = 1000\timediff;
time2 = time;
}

There you make timediff = time (which equals sdl_gettick()) - time2 (which equals... uhm... nothin! Just some random junk value). Set time2 to 0 the first time you run it.

And secondly, is that loop meant to be run in a main loop? Cause if you exit that function and later returns to it, you wont have the values left. Since the variables are decleared locally they will dissapear when they are out of scope (correct me if Im wrong here, Im a beginner coder myself). A way to get around this is to use global variables. But since I dont like those, and I have a fps counter in nearly every single game I make, Ive made a fps counter class.

Hope I at least was to some help, good luck. :)
Thanks for all replies. Using your tips i managed to fix fps problem.

About blinking problem; whole SDL initialization code i have written basing on cone3d tutorials, i'm using double buffering althought i don't really know what it does:\. In function drawing scene i'm using SDL_Flip() function. anyway it's not the biggest problem right now i can work on it later.

About my last question: i guess my explanation was pretty confusing. I simply want to render many images on one surface instead of creating new surface for each image.

This topic is closed to new replies.

Advertisement