Jump to content
  • Advertisement
Sign in to follow this  

SDL Camera Interaction Problem

This topic is 2888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I have a bit of a problem.

I'm working on a C++ SDL game. I just recently inputed the ability to scroll through the level with a camera. However, there is a problem. My game is turn based, and the character can fire his bullet past the limits of the camera screen. I want the player to know where the bullet lands, so I decided I would make the camera follow the bullet, keeping the bullet in the middle of the screen until it hits something.

However, for some reason, when I input the code for following the bullet with the camera, the bullet starts off to the side of the character, instead of from his gun. Without the camera following, the bullet starts from his gun as planned. I'm not completely sure why this is happening, but it seems that the bullet doesn't want to travel separately from the camera, and all the changes made with the position of the camera applies to the bullet as well.

Here is some code I have:

When the "Fire" button is clicked:
//Make the bullet position the same as the player position

Bulletx = ((Player1x) - camera.x);
Bullety = ((Player1y) - camera.y);

In function Bullet::move() :
//Move the Bullet

Bulletx += Velx;
Bullety += Vely;

//Make the camera follow the bullet
camera.x = ( Bulletx + bullet->w/2 );camera.y = ( Bullety + bullet->h/2 );

In function Bullet::show() :
//Show the bullet
apply_surface( Bulletx - bullet->w/2, Bullety - bullet->h/2, bullet, screen );

Any ideas as to what I'm doing wrong, or what I can do to fix this problem? Thanks.

Share this post

Link to post
Share on other sites
Looking back on this, I think I may have put this question in the wrong section. I should probably have put it in "Alternative Game Libraries" or something. Should I repost it there? Or just leave it here?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!