Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Camera Help

Author
Message
JustBlaze 7204
17
Years of Service
User Offline
Joined: 14th Sep 2007
Location:
Posted: 2nd Nov 2007 05:17
Is there a way to have a camera follow a sprite. I am having trouble figuring out how to have a camera follow the sprite. Thanks in advance.
Dr Schnitzengruber
18
Years of Service
User Offline
Joined: 19th Jul 2007
Location: C:/Projects/failed/ schnitzengruber
Posted: 3rd Nov 2007 05:17
Well, to make a camera follow something, you make the sprite stay in the same place while the background moves around it. There are sevral ways to do this but the simplest is to subtract every images position by the position of the camera

e.g.



the answer to life the universe and everything = 42
MonoCoder
19
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 6th Nov 2007 20:10 Edited at: 6th Nov 2007 21:13
Example 1, move the mouse to move the camera.




Example 2, use the arrow keys to move the camera.




Example 3, using some slightly more advanced data handling methods. Use the arrow keys to move the camera.




Example 4, same as example 3, but uses cloggy's d3d plugin to draw stuff much faster (if you don't have, I suggest you get it- search it)




Example 5 - Again, building on example 4, allows you to move the sprite with the mouse. You'll notice that, while the sprite is positioned at the actual location of the mouse, it is drawn at an offset- that offset is the camera's position. So basically:

Sprite is at:
mousex(), mousey()
But is drawn at:
mousex() - camx, mousey() - camy




Hope my endeavors help.

EBA; FUI; Mario Land Ripoff.
Every time you post a joke in the form of code, mace yourself.
JustBlaze 7204
17
Years of Service
User Offline
Joined: 14th Sep 2007
Location:
Posted: 7th Nov 2007 02:58
Thank you very much this has helped me out a lot.
Dark Dragon
18
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 7th Nov 2007 03:34 Edited at: 7th Nov 2007 03:35
what they said Just remember to subtract from all the enemy's x and y positions,too.

Login to post a reply

Server time is: 2025-08-09 02:09:26
Your offset time is: 2025-08-09 02:09:26