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: http://youtu.be/8piWyjfDgbI

  • \$\begingroup\$ 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? \$\endgroup\$
    – olevegard
    May 14, 2013 at 18:30

1 Answer 1

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.

  • \$\begingroup\$ 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. \$\endgroup\$
    – SRG3006
    May 14, 2013 at 19:07
  • \$\begingroup\$ 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. \$\endgroup\$
    – olevegard
    May 14, 2013 at 19:11
  • \$\begingroup\$ 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(): pastebin.com/ZGhEe3c8 A bool called fireBullet. Replaced the SDLK_SPACE code by setting fireBullet = true; Calling drawBullet() in draw(). \$\endgroup\$
    – SRG3006
    May 14, 2013 at 19:22
  • \$\begingroup\$ @AlexKontos update your main post instead, it's easier to read \$\endgroup\$
    – olevegard
    May 14, 2013 at 19:30
  • \$\begingroup\$ I saw what was wrong, I was calling drawBullet() in drawBullet() by accident! But now I get this REALLY weird sort of output: youtu.be/8piWyjfDgbI (Main post has been updated too) \$\endgroup\$
    – SRG3006
    May 14, 2013 at 19:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .