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 / Help with cameras and trackbars

Author
Message
Yodaman Jer
User Banned
Posted: 6th Feb 2011 20:02
Hey all,

I'm currently testing out a few ideas I have for my level editor (one of the ideas being the ability to move the camera with a "trackbar" or "slider"), and I'm having a little trouble.

I have my program set up so that there's a trackbar on the bottom. This trackbar is made with the Box command, and for the x coordinates I'm using a float variable (x#) that at first holds the value of screen width()/2. Then I have it set up so that when the user has the mouse over it and within 100px of each side and clicks, it moves the box by increasing/decreasing x# depending on mouseX()'s value (positive or negative). This is where I'm having trouble. I'm also using x# to position the camera, which should be at x position 0 when the program first begins. Even though the trackbar is in the center of the screen, it should still keep the camera at x position 0. I thought that by using two different variables and passing the values to and from them that I could get around it, but that resulted in the camera not moving at all.

Here's my code. It's a little sloppy but not too bad:


This is the part I'm specifically having trouble with:


As you can see, it's doing exactly what I'm telling it to do, but I'm just not sure how to make it so that the camera stays at x position 0 even if x# is in the center of the screen (at about 400px). Does anyone have any ideas?

Application attached.

Also, if you right-click, you'll be given a Windows 95-style menu with two options: show or hide object. This is not essential to this program, it's just another test. I left it in for flavor.

Yodaman Jer
User Banned
Posted: 8th Feb 2011 00:10
So...does anybody have any ideas? I'm still stumped. Nothing I try works. I'm beginning to think I should just figure out a different way to control the camera.

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 8th Feb 2011 01:46
Hi,

Quote: "As you can see, it's doing exactly what I'm telling it to do, but I'm just not sure how to make it so that the camera stays at x position 0 even if x# is in the center of the screen (at about 400px). "


You can still use the same variable x# for both the camera and the slider, but you need to minus hald the screen width from x# when positioning the camera.

Replace this:




With this:




I've taken out some lines that I don't think are required: the cursor will never leave the screen so you don't need to check to make sure x# is still on the screen and you don't need to worry about moving the cursor in negative x direction as you are using the position of the mouse, not the direction of movement (if that makes sense).
Yodaman Jer
User Banned
Posted: 8th Feb 2011 01:59
Quote: "you need to minus hald the screen width from x# when positioning the camera."


Oh duh. I feel dumb now. I should've thought of that.

Thanks for the help 29 games, that works great!

Quote: "I've taken out some lines that I don't think are required: the cursor will never leave the screen so you don't need to check to make sure x# is still on the screen and you don't need to worry about moving the cursor in negative x direction as you are using the position of the mouse, not the direction of movement (if that makes sense)."


That makes perfect sense. The reason I was checking the position of x# was to make sure that it didn't "fall" off of the white line, but if I just make the line the entire width of the screen then that won't happen. That would classify as a perfect example of my innate ability to over-complicate simple things.

Login to post a reply

Server time is: 2026-07-16 04:35:43
Your offset time is: 2026-07-16 04:35:43