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 / Make the camera follow an image

Author
Message
FishCube
12
Years of Service
User Offline
Joined: 31st Jul 2013
Location:
Posted: 15th Feb 2014 03:07 Edited at: 16th Feb 2014 06:22
So i am making a game where you are running around a 2d plane and i need the camera to follow the player image as it moves. This might just involve moving the camera as the image moves but i really dont know. Im not good with 3d coding and this is really the first type of 3d thing ive done so yah.

Here is the code:



i know its probably really inefficient but it sorta works. Also if anyone has any suggestions on how to make the building grid bigger and maybe expand the world off of the little screen that would be great. Thanks for the help ahead of time

Ok i think i did something, it is definitely better but now the question arises, how do i make the sprite be in space and not client side? Here is the new game running http://www.mediafire.com/download/htl9cg34jaxq0cp/Building_Game.zip
there are so many questions i have about this but lets just stick to making the character not client side eh?

-FishCube-
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 15th Feb 2014 15:52
Whoa!
What the...?

FishCube
12
Years of Service
User Offline
Joined: 31st Jul 2013
Location:
Posted: 15th Feb 2014 16:41
Quote: "
Whoa!
What the...?"


What is the code really weird or something?

-FishCube-
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Feb 2014 19:54
You don't use camera commands when working in 2D.


Yes, it doesn't really do anything. I even placed in some images so I could run the code and all it does is make a sprite move with the mouse. It's unclear what exactly you're trying to accomplish.

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 15th Feb 2014 20:42
You should check out arrays. This way you can turn things like this:



Into nice for loops:



And this:



into this:



Also, instead of your select scancode() block for user input, I'd suggest using the keystate() function to check each key individually. This way the user can press more than one key at once and the program will actually notice.

About the camera/scrolling thing. I guess the easiest way to do it is to add two variables, e.g. ScrollX and ScrollY (or CamX and CamY or whatever). You can then set those relative to your image position (for instance CamX = myImagePositionX - screen width()/2 etc.) and use these two variables when drawing stuff as well as when interacting with the mouse.
Generally, these two equations summarize it pretty well:
ScreenCoord = WorldCoord - Cam and
WorldCoord = ScreenCoord + Cam
So instead of "mx = mousex()" in one of my codes above you'd say "mx = mousex() + CamX", the same applies for the y coordinates.
And when drawing your boxes, you'd offset the x and y values by -CamX and -CamY respectively.

pcRaider
19
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 16th Feb 2014 03:35
demo code


windowsXp

Login to post a reply

Server time is: 2026-07-07 06:24:43
Your offset time is: 2026-07-07 06:24:43