Continous Swipe

Hi all, how could I implement a continous swipe for a pong game? A swipe control withouth lift the finger from screen.

Could you please describe how you want the pong-bar to react to your input a bit better - than I can probably help.

Swipe up without lift the finger ,paddle go up, always without lift the finger, swipe down, paddle go down, and swipe up, down, up, down, always with the finger on the screen. User could lift the finger too. I have to implement the two swipe system together.

Let’s start with the basics: the system for one player.

Create two variables: fingerIsTouching = false and lastTouchY = 0

Create a runtime touchlistener and let it do something like:

When touch begins, set fingerIsTouching = true (you’ll have to write the code right yourself, something if event.phase == “began” etc…) and lastTouchY to event.y

When touch moves set lastTouchY to event.y

When touch ends or is cancelled set fingerIsTouching = false

Then create an enterFrame listener function, so you get a frameLoop to move your sprite.

In the frameLoop write something like:

if fingerIsTouching then --> if lastTouchY < sprite.y then sprite.y = sprite.y - 5, elseif lastTouchY > sprite.y then sprite.y = sprite.y + 5

What this does is say, if the touch is above the sprite, the move the sprite up. If the touch is below the sprite, move it down.

You’ll have to write out the code properly because what I wrote is just the thinking behind it, and not even any syntax at all.

Could you please describe how you want the pong-bar to react to your input a bit better - than I can probably help.

Swipe up without lift the finger ,paddle go up, always without lift the finger, swipe down, paddle go down, and swipe up, down, up, down, always with the finger on the screen. User could lift the finger too. I have to implement the two swipe system together.

Let’s start with the basics: the system for one player.

Create two variables: fingerIsTouching = false and lastTouchY = 0

Create a runtime touchlistener and let it do something like:

When touch begins, set fingerIsTouching = true (you’ll have to write the code right yourself, something if event.phase == “began” etc…) and lastTouchY to event.y

When touch moves set lastTouchY to event.y

When touch ends or is cancelled set fingerIsTouching = false

Then create an enterFrame listener function, so you get a frameLoop to move your sprite.

In the frameLoop write something like:

if fingerIsTouching then --> if lastTouchY < sprite.y then sprite.y = sprite.y - 5, elseif lastTouchY > sprite.y then sprite.y = sprite.y + 5

What this does is say, if the touch is above the sprite, the move the sprite up. If the touch is below the sprite, move it down.

You’ll have to write out the code properly because what I wrote is just the thinking behind it, and not even any syntax at all.