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.

DarkBASIC Professional Discussion / Camera for 2D sprites?

Author
Message
Yellow Star
14
Years of Service
User Offline
Joined: 22nd Mar 2012
Location:
Posted: 22nd Jul 2012 03:47
I need to make a scrolling effect, But the camera only seems to work with 3D. how do I get the camera to work with 2D sprites?
Aaron Miller
20
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 23rd Jul 2012 08:30
Store global variables, called "g_camX" and "g_camY." (These can be compacted to a type, if you prefer.)

Every time you call "sprite," take the 'x' and 'y' coordinates and subtract them by 'g_camX' and 'g_camY'. Here's some pseudo-code:


(I have no idea if I have the parameters to that command right or not. You'll have to double check.)

Now, whenever you want to scroll, just update your camera variables. Easy enough, right?

Ta-da! Scrolling effect.

There are efficiency issues here, though. You may want to research quad-trees and figure out how to apply those if you run frame rate issues. I have no idea whether DBPro uses a quad-tree for sprites or not. I seriously doubt that it does though. Either way, don't worry about it unless you get reports of low or unusable frame-rates, or are just curious.

Cheers,
Aaron

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Jul 2012 21:20
I have a tutorial that might help you out:
http://dbcodecorner.com/?page=tutorials

"You're not going crazy. You're going sane in a crazy world!" ~Tick

Login to post a reply

Server time is: 2026-07-07 20:23:56
Your offset time is: 2026-07-07 20:23:56