Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a basic side scroller that allows the user to run and jump around. I've used various tutorials to get this far, but I can't seem to get any text to render, no matter what method. I also can't get any images to render outside of my draw() function which is rendered at run time, which I think is my problem. (Is it possible to recall the function again to load another image?)

I can't just give a line of code to show the issue since the whole program is interwoven together:

I'm not asking for someone to go through the code and fix everything, just if you could point me in the right direction, or at least know what is causing the problem that would be great!

(Sorry about having all the code in one file, I'm bad a modularising it and kept on getting errors early on in the project because of it. So for learning purposes it's going to be in one file for now).

Edit: At the moment the priority is to get projectiles working. I've tried SDL_UpdateRect and similar but nothing has helped so far.

Edit #2: SO I've created a new function and have called it on top of the map, like it should do. But now I get a strange output:

share|improve this question
Just a quick comment; you shouldn't limit your frame rate. Make movement according to delta time ( time since last frame ) Also; on what line do you try to draw the text? – olevegard May 14 '13 at 18:30
Thanks for the tip. As for the text, that's not important now so I removed the code since it wasn't doing anything. I need projectiles to work, but for some reason I can't get it to display at all. Otherwise I would've been using link and placed everything in the appropriate functions. – SRG3006 May 14 '13 at 18:38
up vote 2 down vote accepted
SDL_FillRect(screen , &bullet[i].b , 0xFFFF66);

This will fill your screen surface in the SDL_Rect &bullet[i].b

Then later in the same frame, you use drawImage To draw the map over the entire size of screen, covering up the projectiles you filled it up with.

I suggest you add a separate SDL_Surface* for your projectile and draw them in your draw() function.

share|improve this answer
How would I get draw() to only call the projectile when space is pressed? Otherwise if I put a call in draw() it'll render the bullet when the program starts. – SRG3006 May 14 '13 at 19:07
There's several possibilities. My suggestion is to add all active projectiles to a std::vector, then you would just draw the entire vector in draw() A quicker option would be to add a bool to your projectile struct that specifies whether or not it should be drawn. – olevegard May 14 '13 at 19:11
I'm using pure C, so i can't use the std::vector. As for that bool, it gave me an idea but it crashes the program now. What I did: New function drawBullet(): A bool called fireBullet. Replaced the SDLK_SPACE code by setting fireBullet = true; Calling drawBullet() in draw(). – SRG3006 May 14 '13 at 19:22
@AlexKontos update your main post instead, it's easier to read – olevegard May 14 '13 at 19:30
I saw what was wrong, I was calling drawBullet() in drawBullet() by accident! But now I get this REALLY weird sort of output: (Main post has been updated too) – SRG3006 May 14 '13 at 19:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.