Skip to main content
saratogacoach
Inspiring
November 13, 2012
Question

Touch/Drag player paddle

  • November 13, 2012
  • 1 reply
  • 1196 views

Hi,

I'm trying to use a desktop AS3 pong-type game for a mobile deployment. This requires changing the player paddle's movement so that instead of following the mouse up or down on Y, it would allow for touch and be dragged up or down on Y by this touch gesture.

I haven't used touch gestures but have been reading at: http://help.adobe.com/en_US/as3/dev/WS1ca064e08d7aa93023c59dfc1257b16a3d6-7ffc.html

Need some help with scripting this. So far, have adapted the script found in the doc's first example, but cannot get it to work in the AIR/Android simulator/debugger in Flash CS6. I must be doing something wrong. No error messages, but it also doesn't drag the paddle in the debugger/simulator.

Here's the script so far. Any suggestions/help appreciated. Maybe, this needs a different scripting approach all-together?

playerPaddle.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);

playerPaddle.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);

function onTouchBegin(e:TouchEvent) {

    e.target.startTouchDrag(e.touchPointID, false, playerPaddle.y);

    trace("touch begin");

}

function onTouchEnd(e:TouchEvent) {

    e.target.stopTouchDrag(e.touchPointID);

    trace("touch end");

}

The original mouse drag script for the paddle was simple: playerPaddle.y = mouseY;

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
November 13, 2012

use e.currentTarget instead of e.target.

saratogacoach
Inspiring
November 13, 2012

Hi kglad,

Thanks for your suggestion. I substituted e.currentTarget for e.target and even tried changing playerPaddle.y to playerPaddle, but no success. The paddle, using the touch enabled simulator in the AIR debugger did not move.

Not sure how to get a simple drag (Y only) to work in touch mobile.

kglad
Community Expert
Community Expert
November 14, 2012

did you enable the correct panel of the simulator (touch and gesture>tick touch layer>tick touch: click and drag)?