Hello everyone, my name is Brenda and I'm from Argentina.
I'm new using Construct 2 and I find it fascinating!
However I run into a problem when I tried to use the while loop for my mobile game.
What I'm trying to accomplish is to move my sprite to the left or to the right while the user is touching the screen.
So for example, if he touches the left side of the screen, then the sprite would move to the other side.
And it has to stop when the user stops touching the screen.
Here's what I've got so far:
It looks very logical to me but I'm clearly missing something.
When I run my project, everytime I touch the screen, the game freezes and it won't let me do anything else.
Could you help me to find what I'm doing wrong?
Thanks in advance (sorry for my english)
You have to use
Touch Is in Touch
Simple example moving only on X
So Touch| is in touch
system| touch.x < Layoutwidth/2 Sprite|Set X to Self.x-2
And do same for opposite side but inversed
system| touch.x > Layoutwidth/2 Sprite|Set X to Self.x+2
If I do it that way, it works perfect as you said!
But, what I want to do is to gradually accelerate the sprite while the user is touching the screen.
That's why I was using the While loop, to increment the acceleration on every cycle
touch.x<layoutwidth/2 is a loop so
Put your custommovement accelerate 300 in, and put self.x-2 and self.x+2 respectively.
It loops as long as that condition isn't met.
Develop games in your browser. Powerful, performant & highly capable.
You could do that with a variable what increase or decrease.
And I would use ViewportRight not LayoutWidth.
Global number acceleration =0
Touch| is in touch System| add 0.1 from acceleration
system| touch.x < ViewportRight(0)/2 Sprite|Set X to Self.x-acceleration
system| touch.x > ViewportRight(0)/2 Sprite|Set X to Self.x+acceleration
Touch| on any touch end System|set acceleration to 0
Thanks DUTOIT, it worked really good!
Thank you also, Asmodean! I'll try what you said too.