Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
use e.currentTarget instead of e.target.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
did you enable the correct panel of the simulator (touch and gesture>tick touch layer>tick touch: click and drag)?
Copy link to clipboard
Copied
Yes, I did check the touch checkbox plus click and drag. But while the dot simulator appeared, when I placed it over the player paddle and tried click and drag, nothing moved.
I'm not familiar with the touch drag parameters: maybe the last item as playerPaddle.y (or even playerPaddle without adding .y) are not correct?
Since, in mobile maybe a mouse down is interpreted as a touch event, would it be possible to simply set up mouse down and mouse up to start and stop a drag on Y? Not sure what this would look like in AS3, but maybe this could work?