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:
Rem Project: Dark Basic Pro Project
Rem Created: Saturday, February 05, 2011
Rem ***** Main Source File *****
set display mode 800,600,32
set window size 800,600
set text font "microsoft sans serif"
set text size 12
sync on
sync rate 90
make object box 1,5,5,5
position object 1,0,0,15
//position camera slider
x#=screen width()/2
//position camera
position camera 0,0,0
task=1
blue as dword : blue=rgb(0,0,255)
black as dword : black=rgb(0,0,0)
do
ink rgb(255,255,255),rgb(255,255,255)
//draw text
if task=1
show object 1
else
hide object 1
endif
text 0,0,"Camera Position: X:"+Str$(camera position x())+" Y:"+str$(camera position y())+" Z:"+str$(camera position z())
//draw trackbar
line 5,screen height()-30,screen width()-5,screen height()-30
box x#-5,screen height()-50,x#+5,screen height()-10,black
oldClick=click
click=mouseclick()
if mousex() > x#-100 and mousey() > screen height()-50 and mousex() < x#+100 and mousey() < screen height()-10
if click=1 and mousemovex()
x#=mousex()
position camera x#/10,0,0
if x# > screen width()
x#=screen width()
endif
endif
if click=1 and mousemovex()
x#=-mousex()
position camera x#/10,0,0
if x# < 0
x#=0
endif
endif
endif
if click=0 and oldClick=2
active=1
OMX=MouseX()
OMY=MouseY()
endif
if active=1
ink rgb(0,0,0),rgb(0,0,0)
box OMX+1,OMY+1,OMX+152,OMY+202
ink rgb(255,255,255),rgb(255,255,255)
box OMX,OMY,OMX+151,OMY+201
ink rgb(128,128,128),rgb(128,128,128)
box OMX+1,OMY+1,OMX+151,OMY+201
ink rgb(192,192,192),rgb(192,192,192)
box OMX+1,OMY+1,OMX+150,OMY+200
box OMX+2,OMY+2,OMX+32,OMY+198,blue,black,blue,black
//check for mouse hover
if mousex() > OMX+32 and mouseY() > OMY and mousex() < OMX+150 and mouseY() < OMY+20
hover=1
ink rgb(0,5,125),rgb(0,5,125)
box OMX+32,OMY+2,OMX+149,OMY+22
endif
if mousex() > OMX+32 and mouseY() > OMY+22 and mousex() < OMX+150 and mouseY() < OMY+42
hover=2
ink rgb(0,5,125),rgb(0,5,125)
box OMX+32,OMY+22,OMX+149,OMY+42
endif
//print info
ink rgb(0,0,0),rgb(0,0,0)
text OMX+35,OMY+5,"Show Object"
text OMX+35,OMY+25,"Hide Object"
//deactivate menu
if click=0 and oldClick=1
if hover=1 and oldClick=1
if task=0 then task=1
active=0
endif
if hover=2 and oldClick=1
if task=1 then task=0
active=0
endif
endif
endif
sync
loop
This is the part I'm specifically having trouble with:
if mousex() > x#-100 and mousey() > screen height()-50 and mousex() < x#+100 and mousey() < screen height()-10
if click=1 and mousemovex()
x#=mousex()
position camera x#/10,0,0
if x# > screen width()
x#=screen width()
endif
endif
if click=1 and mousemovex()
x#=-mousex()
position camera x#/10,0,0
if x# < 0
x#=0
endif
endif
endif
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.