Reproduce mouse movement

Get help using Construct 2

Post » Sat Mar 29, 2014 11:49 pm

Message: vivalabello can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
HI,

I am trying to make a sprite reproduce the movement of my mouse when i have my left mouse button down. It "works" but, i don't understand why, the sprite move faster than the mouse. So this is my capx :
https://dl.dropboxusercontent.com/u/23569593/FORUM%20C2%20-%20Panda/Panda%20Party%20Night.capx
I'm think it's a problem with the math but i don't know where... :s
Help ?
B
7
S
1
Posts: 30
Reputation: 787

Post » Sun Mar 30, 2014 1:05 am

yea i took a stab at it, but my math skills suck.. but i made this really rough and dirty almost right capx you can try out.. it isn't properly setup, the coordinates are out of whack but notice that it does track with the mouse movement without flying off the screen https://www.dropbox.com/s/noiijo4afpbbf ... mouse.capx

i think there just needs to be some better math to establish where X and Y of the mouse and the X and Y of the sprite are to insure they move in unison.
B
59
S
9
G
1
Posts: 939
Reputation: 6,545

Post » Sun Mar 30, 2014 2:04 am

not sure what you're trying to do, if you just want the sprite to follow the mouse

on left mouse down,
set sprite position to x = mouse.x and y = mouse.y

using arrays would only be needed if you want to record the mouse movement
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Sun Mar 30, 2014 1:44 pm

Part12Studios : Thanks. The movement works but i don't understand how to not move the sprite when you click on the left button. It's come from this part but i don't find a way to skip that part.
"MouseDown = 1
Trigger once
->Set MouseX to mouse.X-sprite.X
->Set MouseY to mouse.Y-sprite.Y"
I want that the sprite keep it's initial position when I left clicked.


Vtrix : I don't want the sprite to follow the mouse, I want it to reproduce the mouse movement. I want that when i clicked on the left mouse button and, for example, i go to the left with my mouse the sprite go to the left to. But i don't want the sprite to teleport to the mouse position. I want it to keep it's initial position and reproduce the movement of the mouse. Like you said, i know how to make a sprite follow the mouse but i don't know how to make a sprite reproduce the mouse movement.
B
7
S
1
Posts: 30
Reputation: 787

Post » Mon Mar 31, 2014 4:00 pm

OK i finally found how to do it. I change this :
->Set MouseX to mouse.X-sprite.X
->Set MouseY to mouse.Y-sprite.Y
Into this :
->Set MouseX to sprite.X-mouse.X
->Set MouseY to sprite.Y-mouse.Y

Thanks a lot !
B
7
S
1
Posts: 30
Reputation: 787


Return to How do I....?

Who is online

Users browsing this forum: rayolf and 16 guests