
Код AS1/AS2:
package
{
import flash.display.MovieClip;
import flash.ui.MultitouchInputMode;
import flash.events.*;
import flash.ui.Multitouch;
public class Main extends MovieClip
{
private var _hero_mc:hero_mc;
private const RAD_TO_DEGREES:Number = 180 / Math.PI;
private var _hero_body_ti:int = 0;
private var _hero_foot_ti:int = 0;
public function Main()
{
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
_hero_mc=new hero_mc();
_hero_mc.x = 300;
_hero_mc.y = 400;
addChild(_hero_mc);
_tap_fire_mc.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchFireBegin);
_tap_motion_mc.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchMotionBegin);
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
}
public function onTouchMovie(e:TouchEvent):void
{
if (e.touchPointID == _hero_body_ti)
{
var bDx = e.stageX - _tap_fire_mc.x;
var bDy = e.stageY - _tap_fire_mc.y;
var mAngleD = Math.atan2(bDy,bDx) / Math.PI * 360;
var _hero_rotate = - Math.atan2(bDx,bDy) * RAD_TO_DEGREES;
_hero_mc.body_hero.rotation = _hero_rotate;
}
if (e.touchPointID == _hero_foot_ti)
{
var sDx = e.stageX - _tap_motion_mc.x;
var sDy = e.stageY - _tap_motion_mc.y;
var dirAngleD = Math.atan2(sDy,sDx);
background_mc.x -= 5 * Math.cos(dirAngleD);
background_mc.y -= 5 * Math.sin(dirAngleD);
}
}
public function onTouchFireBegin(e:TouchEvent):void
{
if (_hero_foot_ti==0&&_hero_body_ti ==0)
{
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMovie);
}
_hero_body_ti = e.touchPointID;
}
public function onTouchMotionBegin(e:TouchEvent):void
{
if (_hero_foot_ti==0&&_hero_body_ti ==0)
{
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMovie);
}
_hero_foot_ti = e.touchPointID;
}
public function onTouchEnd(e:TouchEvent):void
{
if (e.touchPointID == _hero_body_ti)
{
_hero_body_ti = 0;
}
if (e.touchPointID == _hero_foot_ti)
{
_hero_foot_ti = 0;
}
if (_hero_foot_ti==0&&_hero_body_ti==0)
{
stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMovie);
}
}
}
}
Код не оформлял, просто хотел понять принцип.