C++ and SDL

Started by
23 comments, last by Smacker_626 21 years, 7 months ago
Looking quickly, I looks like you draw the scene once, then go into the game loop, and keep processing key presses. You need to keep re-drawing the screen within the ''for'' loop in your message pump.
Advertisement
Here it is i tested this one

and jakar thanks for helping but umm why would i want to do that?(i was going to do it in the first place also though this was just because i was bored)

and ELCrazon that was because i forgot to uncomment the fLoadImages(); line in the pump and fBlitImg and fBlitImg2 Frees the Surface each time (and i had the SDL_FreeSurface line commented out so it had a huge memory proplem) so it couldnt Blit it

I hope thats everything i wanted to say lol


--------------------signature--------------------

Looking for usefull, interesting resources

WELL DONT LOOK HERE>>http://www.dragonruins.com/

but its still fun to have a look around
I just noticed where you are redrawing your screen (I can''t believe I missed it with so many calls). It is hard to follow, and very easy to lose control of the situation like that. In my opinion, drawing the screen should be called from one point. As for your problem, as long as it is getting to the ''if'' statement, I can''t see why it would have a problem adding 1. I am only viewing this code through the browser, and can''t try and compile it at the moment.
i put even newer files on the serv so click the link up there^^^

also does either of you know how to make it not so CPU Intensive i had to take out the SDL_Delay(1); it wasnt running smooth but know it stays at 99% CPU Usage (like always)

and how would you get input from 2 different keys at the same time:

say it was like galaga how could i make the ship move back and up by pressing the up and left keys (its only getting input from 1 key at a time right now)

--------------------signature--------------------

Looking for usefull, interesting resources

WELL DONT LOOK HERE>>http://www.dragonruins.com/

but its still fun to have a look around

[edited by - Smacker_626 on August 27, 2002 4:55:15 PM]
Another problem I see is that you keep loading the images each pass. You also keep redirecting the surface pointer to a newly loaded image without getting rid of the old image (eating up memory). Try loading all the images once, and have an image for button1 and another for button2.

I saw that you are releasing the images once you draw them, but I can't easily tell if you are getting them all. From your description of your memory problem before, I would guess that you are missing the release of some. This is one reason you should allocate your resources in the beginning, then release them at the end. Another reason is that it takes up too much CPU time.

[edited by - jakar on August 27, 2002 5:11:24 PM]
quote:Original post by jakar
Another problem I see is that you keep loading the images each pass. You also keep redirecting the surface pointer to a newly loaded image without getting rid of the old image (eating up memory). Try loading all the images once, and have an image for button1 and another for button2.


I think you have a point but about not getting rid of the old image your wrong if you look at fBlitImg (and fBlitImg2) right before return; i call SDL_FreeSurface(srcSurf); to free that surface

and umm besides me having to redo the loading problem could you help me with this: (it works fine accept when it comes to the if statements it runs both of them fine accept for the fact it lets you click anywhere could you help me with that?)


  void fCheckMousePos(){	int tempx, tempy;	tempx = ((xpos) + (128));	tempy = ((ypos) + (128));	SDL_GetMouseState(&mxpos, &mypos);	mxpos = event.button.x;	mypos = event.button.y;	if (mxpos >= xpos && mxpos <= tempx && mypos >= ypos && mypos <= tempy && buttonPressed == 1)	{		fLoadImages();		fDrawScreen();		cout << "Button Pressed!\n";	}	else if (mxpos >= xpos && mxpos <= tempx && mypos >= ypos && mypos <= tempy && buttonPressed == 0)	{		fLoadImages();		fDrawScreen();		cout << "Button Released!\n";	}	return;}  


--------------------signature--------------------

Looking for usefull, interesting resources

WELL DONT LOOK HERE>>http://www.dragonruins.com/

but its still fun to have a look around
Well im gonna go eat ill be back in a couple minutes i guess

if u fix the problem just post it on here but most of all try to ansewer my post (3rd to last post)

Thanks for all the help

--------------------signature--------------------

Looking for usefull, interesting resources?

WELL DONT LOOK HERE>>http://www.dragonruins.com/

but its still fun to have a look around
ok im back


--------------------signature--------------------

Looking for usefull, interesting resources?

WELL DONT LOOK HERE>>http://www.dragonruins.com/

but its still fun to have a look around
use
SDL_GetKeyState
to make it so you can detect two button presses at once...

ummm i''ll go look for some old code so i can show you how it works....

ok, i found some...


  int* keys;...keys = SDL_GetKeyState(NULL);if ( keys[SDLK_PAGEUP] == SDL_PRESSED ) {	z-=0.02f;}if ( keys[SDLK_PAGEDOWN] == SDL_PRESSED ) {	z+=0.02f;}if ( keys[SDLK_UP] == SDL_PRESSED ) {	xspeed-=0.01f;}if ( keys[SDLK_DOWN] == SDL_PRESSED ) {	xspeed+=0.01f;}if ( keys[SDLK_LEFT] == SDL_PRESSED ) {	yspeed-=0.01f;}if ( keys[SDLK_RIGHT] == SDL_PRESSED ) {	yspeed+=0.01f;}  


piece of cake...

you use SDL_PumpEvents to update the key state array

read the sdl docs for more info

This topic is closed to new replies.

Advertisement