moving objects with mouse

Get help using Construct 2

Post » Mon Nov 28, 2011 6:53 am

Hiya,

Just a couple of quick questions regarding moving objects with the mouse.

The code i have to do this is as follows :

Mouse Left Button is down   object   set position to (mouse.x,mouse.y) object pick instance with UID
        object.UID
Mouse   Cursor is over object

now firstly when you move the object with the mouse it is very easy to leave it behind if you move the mouse too fast, is there a way to have the object latch onto the mouse cursor so this doesn't happen?

secondly when you move the object over another object (of the same type) one of the objects disappears.

and finally if you declare two different objects with similar code to above then when one object is moved over the other object, they latch on.

Any help would be appreciated, thanks in advance
B
12
S
1
G
2
Posts: 18
Reputation: 1,726

Post » Mon Nov 28, 2011 9:04 am

[code]Mouse: on left button clicked on Sprite
      -> Sprite: set selected to True
Mouse: [invert] left button is down
      -> Sprite: set selected to False
Sprite: Is selected
      -> Sprite: set position to Mouse.X,Mouse.Y[/code]Yann2011-11-28 09:05:06
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Nov 28, 2011 10:03 am

hi thanks for the response, i am kinda new at this stuff, what do you mean by set selected to True?
B
12
S
1
G
2
Posts: 18
Reputation: 1,726

Post » Mon Nov 28, 2011 10:11 am

k so this is what i've got :
set a boolean variable to the object

Mouse on left button click   object   set variable as true
pick instance with UID
        object.UID
Mouse   Cursor is over object

Mouse Left Button is down   set position(mouse.x,mouse.y)
pick instance with UID      set variable false
        object.UID

it works quite well BUT, as soon as i click one of the objects, the instances of the object all disappear...weird?
B
12
S
1
G
2
Posts: 18
Reputation: 1,726

Post » Mon Nov 28, 2011 3:27 pm

you dont need the uid, if you use the on object clicked, that object will be picked, in the same event you set the boolean "selected" of that object to true

object boolean selected is true set position to mouse

Mouse: [invert] left button is down > means when you release the mousebtn
set selected to false

ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests