That being said vectorToAngle rotates to an x and y position supplied in the parameters but if you're dragging it then it's x and y position would be the mouse pointer which would be close to the centre of the actor
That being said vectorToAngle rotates to an x and y position supplied in the parameters but if you're dragging it then it's x and y position would be the mouse pointer which would be close to the centre of the actor
i have done my drag but come to the rotate, it cant rotate well, it just moving
This is what I'd probably try if you want to try it yourself before then
When you start to drag your character (not while you're dragging), store it's start position in two game attributes i.e. game.startDragX and game.startDragY
While dragging it constrain the actor angle to vectorToAngle(game.startDragX, game.startDragY) - 180
What this should do (without the -180) is rotate the actor to look towards the start drag point, and the -180 part should flip the angle to look away from the start point.
Although my vectorToAngle example was incorrect above I was on the right tracks. Here's the file I promised
I set it so that it updates the previous x and y position every second, while it's being dragged. You don't need to do this, you could just set the previous x and y postion with the actors position when it's stationary and not being dragged/touched.
If you find the rotation a little snappy at times then throw in a interpolate to smoothen the rotation.
Although my vectorToAngle example was incorrect above I was on the right tracks. Here's the file I promised
I set it so that it updates the previous x and y position every second, while it's being dragged. You don't need to do this, you could just set the previous x and y postion with the actors position when it's stationary and not being dragged/touched.
If you find the rotation a little snappy at times then throw in a interpolate to smoothen the rotation.
I think in the bubble ball game, the objects are dragged into place. Then you tap right or left to rotate the objects.
If this is what you are trying to achieve, you could check for mousedowns and then check to see if the mouse is left or right of the object. If it is on the left side of the scene, then rotate counterclockwise. If the mouse is on the right side, then it rotates clockwise.
I think in the bubble ball game, the objects are dragged into place. Then you tap right or left to rotate the objects.
If this is what you are trying to achieve, you could check for mousedowns and then check to see if the mouse is left or right of the object. If it is on the left side of the scene, then rotate counterclockwise. If the mouse is on the right side, then it rotates clockwise.
how to determine left or right?can you do a demo to me?thx
Oh... so you didn't want it to rotate in the direction it's dragged then!
To only rotate one at a time, and only the one you last dragged, try the following:
• add two integer game attributes called bubbleCounter, and lastBubbleDragged • add an integer attribute to to the actor called bubbleID • at the top of the bubble actor add a change attribute to increase the game.bubbleCounter by one. • underneath that add a change attribute to set the self.bubbleID with game.bubbleCounter. • in the drag rule on the actor add a change attrubute to set game.lastBubbleDragged with self.bubbleID • on the rule where you're rotating the actor add "if self.bubbleID = game.lastBubbleDragged".
Oh... so you didn't want it to rotate in the direction it's dragged then!
To only rotate one at a time, and only the one you last dragged, try the following:
• add two integer game attributes called bubbleCounter, and lastBubbleDragged • add an integer attribute to to the actor called bubbleID • at the top of the bubble actor add a change attribute to increase the game.bubbleCounter by one. • underneath that add a change attribute to set the self.bubbleID with game.bubbleCounter. • in the drag rule on the actor add a change attrubute to set game.lastBubbleDragged with self.bubbleID • on the rule where you're rotating the actor add "if self.bubbleID = game.lastBubbleDragged".
Oh yeah, man..it works well and it is i want...thx a lot...=)
Comments
If so, take a look at the vectorToAngle function, that may give you what you need.
When you start to drag your character (not while you're dragging), store it's start position in two game attributes i.e. game.startDragX and game.startDragY
While dragging it constrain the actor angle to vectorToAngle(game.startDragX, game.startDragY) - 180
What this should do (without the -180) is rotate the actor to look towards the start drag point, and the -180 part should flip the angle to look away from the start point.
I set it so that it updates the previous x and y position every second, while it's being dragged. You don't need to do this, you could just set the previous x and y postion with the actors position when it's stationary and not being dragged/touched.
If you find the rotation a little snappy at times then throw in a interpolate to smoothen the rotation.
If this is what you are trying to achieve, you could check for mousedowns and then check to see if the mouse is left or right of the object. If it is on the left side of the scene, then rotate counterclockwise. If the mouse is on the right side, then it rotates clockwise.
When the mouse is down
-- When game.mouse.position.X < game.screen.size.width/2
----rotate counterclockwise
--otherwise
----rotate clockwise
If you can tell us how you want to solve this, I am sure someone on the forum will be able to give you hints on how to do it.
To only rotate one at a time, and only the one you last dragged, try the following:
• add two integer game attributes called bubbleCounter, and lastBubbleDragged
• add an integer attribute to to the actor called bubbleID
• at the top of the bubble actor add a change attribute to increase the game.bubbleCounter by one.
• underneath that add a change attribute to set the self.bubbleID with game.bubbleCounter.
• in the drag rule on the actor add a change attrubute to set game.lastBubbleDragged with self.bubbleID
• on the rule where you're rotating the actor add "if self.bubbleID = game.lastBubbleDragged".