Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Don't understand something


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 cold_heats_.--.   Members   -  Reputation: 127

Like
0Likes
Like

Posted 27 June 2012 - 05:50 PM

Hi there. I'm trying to make a simple SDL program.
After setting the video mode and loading the background and sprite circle, basically it takes the mouse pointer coordinates and draws the circle at that location.
This is the code
[source lang="cpp"]#include <SDL/SDL.h>#include <SDL/SDL_Image.h>int main(int argc, char** argv){ SDL_Init(SDL_INIT_EVERYTHING); SDL_Surface *screen=NULL; SDL_Surface *circle=NULL; SDL_Surface *backgrd=NULL; SDL_Rect crc; crc.w=160; crc.h=120; crc.x=crc.y=0; circle=IMG_Load("circle.png"); backgrd=IMG_Load("img.bmp"); screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); bool run = true; SDL_Rect mouser; mouser.x=0;mouser.y=0; SDL_Event event; SDL_BlitSurface(backgrd,NULL,screen,NULL); SDL_Flip(screen); while(run) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: run = false; break; case SDL_MOUSEBUTTONDOWN: mouser.x=event.button.x; mouser.y=event.button.y; break; } } SDL_BlitSurface(backgrd,NULL,screen,NULL); SDL_BlitSurface(circle,NULL,backgrd,&mouser); SDL_Flip(screen); SDL_Delay(2000); } SDL_FreeSurface(backgrd); SDL_FreeSurface(circle); SDL_Quit(); return 0;}[/source]
I've set the delay so I can see the sprite before it gets deleted.
The problem is, sprites do not get deleted, that is what I don't understand.
I mean , shouldn't they be "overwritten" each time I call SDL_Blitsurface at line 46 ?
Isn't that how games are rendered ? (Load background, load tiles, load sprite etc etc )

Edited by cold_heats_.--., 27 June 2012 - 05:51 PM.


Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 16413

Like
1Likes
Like

Posted 27 June 2012 - 05:54 PM

You draw the background over top of the screen, then draw the circle over top of the background. At no time does your code actually clear what's already been drawn to the background :-)

#3 BeerNutts   Crossbones+   -  Reputation: 3018

Like
0Likes
Like

Posted 27 June 2012 - 09:05 PM

What ApochPiQ said. For what you're trying to do, you should be blitting the Sprite to the screen. So, when you blit the background again, it will overwrite the old background, and the sprite that was drawn there.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#4 cold_heats_.--.   Members   -  Reputation: 127

Like
0Likes
Like

Posted 27 June 2012 - 11:39 PM

Wow, that was so simple !
Thank youu.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS