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.

Newcomers DBPro Corner / Confused about cameras in 2d enviroment

Author
Message
xguild
15
Years of Service
User Offline
Joined: 19th Oct 2008
Location:
Posted: 20th Nov 2009 12:35
Im a bit confused about the usage of cameras in a 2d enviroment.

It doesn't appear that most of the commands related to cameras that normally work fine in a 3d enviroment, in particular when it comes to following objects, or controling the camera itself work the same in a 2d enviroment.

For example there is no "Cammera Follow Sprite" command.

If i create a sprite and set it up to control it using arrow keys how would I get the default camera to follow the sprite?

Newbie Alert
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Nov 2009 02:41
Unless you are working with 3D specifically there is no camera.

In 2D, you just have a grid of dots (pixels). You place/move things on there to give the impression of movement - like scrolling.

Although the 2D screen co-ordinates run from 0-799 and 0-599 in 800x600 screen mode, you can still use values outside these ranges to place things (images/sprites) off the screen.

Just think of the camera being locked in place and instead of moving the camera to point at objects, you move the objects into the view of the camera.

TDK

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 21st Nov 2009 18:32
If you want the "camera" in a 2D environment to follow a sprite, then you might consider moving the environment, and keeping the sprite centered.

There are lots of posts and snippets about scrolling terrain or backdrops, check 'em out!

Rich

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 24th Nov 2009 06:20
There is no 2d camera built into DBPro, unfortunately.

So... a 3d camera rotates, pans, and zooms. The easiest (and fastest) 2d camera to make, would be one that pans. Left/right, up/down. You would just take your object's "World" coordinates, and subtract them by your camera coordinates. A bit harder than this would be adding in scaling. You would multiply the object's world coordinates by a scale factor, and then subtract them by your camera coordinates.

Even harder, adding in rotation. That involves rotation matrices, and trig. Basically, you take the object's world coordinates, rotate them by the negative camera angle, scale them, then subtract...

I wrote some code to do just that in the code snippets board.

http://forum.thegamecreators.com/?m=forum_view&t=157447&b=6

It's kinda slow though, and I've only tried it out with circles and lines.

Still, i'd recommend simple movement, from side to side. Rotation and scaling doesn't seem to add much to a 2d game (rotation especially)

Login to post a reply

Server time is: 2024-09-28 12:21:17
Your offset time is: 2024-09-28 12:21:17