[FIXED]Set Actor Y value to follow mouse's Y while mouse is down

Sunny

  • Posts: 53
I have an actor moving across the screen (x-speed = 10) from left to right.

I want the actor to be able to have its y-position change if the user presses on the actor and keeps his finger on the screen (doesn't have to be on the actor). I also want the actor to maintain its speed.

I currently have the following code, which causes the game to freeze if i click on the actor.

Any help will be appreciated!

« Last Edit: February 05, 2015, 05:01:19 am by Sunny »

Bhoopalan

  • Posts: 1018
I'm afraid your question isn't clear. From your image attachment, I assume that you want x value to change on regular interval and y value should be the y value of mouse once mouse is clicked. Is that correct?
If I helped you at anytime, help me back build my twitter followers :)
https://twitter.com/imbhoopalan

Hectate

  • *
  • Posts: 4643
The "While" block does not do what you think it does. You can read the help information about it, but basically it is a "while loop" which prevents anything else from happening - this is your game locking up.

Instead you need to use a "IF" statement there. This means you will be saying "if the mouse is down" do the stuff.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

panda84

  • Posts: 28
Hi,

The while and repeat until loops don't  work unless a definite exit to the loop is present. For example: while(true) would cause the game to freeze. That is what's happening with while mouse is down. I think you will have to use the 'When Updating' event in conjunction with the multitouch release and dragged event and the on actor event too. I can give more details about how to do it this way if needed.

Hope that helps.

Sunny

  • Posts: 53
Hey, thanks for the replies, here is what I want to do:

An actor is moving across the screen
If the user presses down on the actor, while the mouse is still down I want the actor's y to follow the mouse's y.
I want the actor to continue moving in its x direction too.
It also does not matter if the user's touch leaves the actor, as long as the mouse is still down, the actor will follow in the y

Does that make sense :P

Thanks

Bhoopalan

  • Posts: 1018
The "While" block does not do what you think it does. You can read the help information about it, but basically it is a "while loop" which prevents anything else from happening - this is your game locking up.

Instead you need to use a "IF" statement there. This means you will be saying "if the mouse is down" do the stuff.

This should work as far as I see. Replace 'while' with 'if'. Let us know how it goes. All the best
If I helped you at anytime, help me back build my twitter followers :)
https://twitter.com/imbhoopalan

Sunny

  • Posts: 53
I replaced it with an IF, however, the actor only moves slightly when I click, it does not do anything after even when my mouse is still clicked.
I attached my code

EDIT: Does "mouse was pressed on self" mean pressed down and released? or just pressed down? because I think I am looking for IF mouse is pressed down, and while the mouse is still pressed (doesn't have to be on actor anymore) then follow mouse's y

panda84

  • Posts: 28
'mouse was pressed on' doesn't seem to stay true for long ... I think it might go back to false when the mouse is dragged .. you would expect that only to happen when the mouse is released. I've attached a screen shot that should work instead.

Sunny

  • Posts: 53
Sweet! That works, I believe the "if mouse is down" is redundant as well? This code seems to work:

panda84

  • Posts: 28
Yeah I just realised the 'if mouse is down' is not needed :)