App inventor: How do I move a sprite as long as button is pressed?

I recently wanted to develop a Brick Braker game in App inventor. But I keep coming across the same problem again and again. I'm trying to get the sprite to move as long as the button is pressed, so the longer the button is pressed the further the sprite moves, in ten steps. How do I do that? So far i only managed to get the sprite to move 10 pixels with every single click, but it would be stupid if you have to spamm the button all the time. Haven't found the solution on google

1 Like

Use touch down and touch up blocks from a button to set a variable to true or false. Then inside a clock timer, place an if statement that does what you wanted to do.

Thanks for the quick answer, but I still don't know exactly how to do it...I tried a little bit, but I still didn't make it. Could you potentially send me a screenshot?

1 Like

Show your dump of the blocks you tested on.


This is what I have so far, but when I launch my app, the sprite moves left till the edge is reached even tho I have pressed nothing

Rather not after launching the application, but after pressing a button. Don't use a loop, just a clock. Start the clock after pressing the button and turn off the clock after releasing the button. In the clock, move the sprite.

Ok, thanks I finally made it :smiley:

Here is my solution:

And what is this "brickBrakerMove" variable for?

You are right, I don't need it anymore :wink:

Heyy, I got one more question. I want my sprite, which I can move in the brick breaker game, to always be at the bottom of the screen. I haven't found a way yet to make sure that no matter how big the phone is, the sprite is always at the bottom of the screen. I tried set sprite1 y to buttonLeft hight + 10 but this didn't work...what can I do?

And the same with the bricks

To set sprites at the bottom, use Canvas1.Height - Sprite.Height for the y value.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.