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 / move an object to mouse x y

Author
Message
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 24th Sep 2004 00:37
Hello one and all
What is the best way to move an object to a new X Y pos by moving the mouse and clicking a spot on a map and having the the object move to that pos.?
I have a plane that the camera is looking vert. down on. I have objects planes texture with 2d sprites and need to move the around.
here is the code I have so far.

Rem ***** Main Source File *****
sync on
sync rate 60
camx# = 130.0
camy# = 500.0
camz# = -550.0

autocam off
position camera camx#, camy#, camz#
point camera camx#, camy#, camz# : rem pointing straight down!
set ambient light 50
make light 1

make object plain 4,16,16
LOAD IMAGE "test1.bmp", 4,1
texture object 4,4
position object 2,130,460,-1


make object plain 2,16,16
LOAD IMAGE "solder 2.bmp", 2,1
texture object 2,2
position object 2,130,500,-1

make object plain 3,16,16
LOAD IMAGE "solder 1.bmp", 3,1
texture object 3,3
position object 3,130,480,-1

make object plain 1,2500,2500
load image "cwbg2.bmp",1
texture object 1,1
do
if upkey() then inc camy#,1.0
if downkey() then dec camy#,1.0
if leftkey() then dec camx#,1.0
if rightkey() then inc camx#,1.0
if inkey$() = "a" then inc camy#,1.0
if inkey$() = "z" then dec camy#,1.0
if camx# > 800.0 then camx# = 800.0
if camx# < -800.0 then camx# = -800.0
if camy# > 913.0 then camy# = 913.0
if camy# < -900.0 then camy# = -900.0

`controls

`We'll want to be able to control the camera, so we'll do that here.
control camera using arrowkeys 0,1,1

`The way the pick object command works, is you'll want to set something eqaul to it.
`In this case we use "p" (For pick if you didn't guess. ), so we can identify
`whatever object is picked with p.
`To find out which object we're picking, we'll use the mousex() and mousey() commands
`in the first two spaces for the pick object command. After that, we put the range of
`objects we'll be using. In this case we have five objects, so our range is 0-5.
`If you had 500 objects, it would be 0-500. Or maybe you only want to select the first
`100, then 0-100. In any case, the last two spaces for syntax are for the objects you
`want to pick.
`(**NOTE This is a handy place to put variables if you'll be periodically be
`creating objects.**)
p=pick object(mousex(),mousey(),2,4)
set cursor 0,0
`If p isn't picked, this is what we'll do. We'll say nothing is picked
`and color all the objects white.
if p=0
print "No objects selected"
for a = 1 to 5

next a
`If an object is picked, we'll print which one is picked, and color it yellow.
else
print "Object ";p;" is selected."

endif


sync


position camera camx#,camy#,camz#
loop


I am going to have many sprites plane objects and I want to be able to move then around the map. Once I pick one and it strat to move to a new pos. I want to be able to go to the next object and move it while the other object is still moving to the new pos.

Tanks you renny
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 24th Sep 2004 01:50
I looked in the Dark Basic pro reference manual for the comm. colorkey and could not find it. I need to know how to use that comm. to
thanks renny
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 24th Sep 2004 03:00
Set image colorkey sets teh colour that will be transparent in the image. Set it before you laod to the colour you'll use, by default it's black.

As for mouse x/y, just use pick screen().

Specify a distance fro mteh camera to project a point plus the x/y co-ords, and the position will be stored int he get pick vector x/y/z commands...


...almost. The info stored there is actually the project point's offset from the camera position, so to position an object at the mouse point 5 units from the screen do this:

pick screen mousex(),mousey(),5.0
position object get pick vector x()+camera position x(),get pick vector y()+camera position y(),get pick vector z()+camera position z()

If you want to position the obejct on an object at the mouse postion, you first need to know how far the objects surface is from the camera. To do that, use the intersect object command.

You specify an imaginary 3d line (eg going from teh camera to a position far infront of the camera) and DBP checks along that line to see if that trajectory hits any part of a specified object. If it does, it'll return the distance to that intersection. And you can use that in pick screen().

Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"

Login to post a reply

Server time is: 2025-06-09 03:58:52
Your offset time is: 2025-06-09 03:58:52