我试图让我的播放器通过触摸屏幕进行拍摄,我已经完成了,唯一的问题是它只是在我触摸播放器时拍摄,但我想要的是能够通过触摸任何部分来拍摄屏幕,有什么建议吗?我很感激。
import flash.display.MovieClip;
import flash.events.AccelerometerEvent;
import flash.sensors.Accelerometer;
import flash.events.Event;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.events.TouchEvent;
import flash.system.TouchscreenType;
public class spaceShooter extends MovieClip {
public var mcPlayer:MovieClip;
private var theAcc:Accelerometer = new Accelerometer();
private var aMissileArray:Array;
public function spaceShooter() {
// constructor code
///////////////////////////
///////Missile Array///////
///////////////////////////
aMissileArray = new Array();
//////////////////////////////////////////////////
//////////////Touch-Tap Missile///////////////////
//////////////////////////////////////////////////
addEventListener(TouchEvent.TOUCH_TAP, onTouch);
//////////////////////////////////////////////////
//////////Player Movement Accelerometer///////////
//////////////////////////////////////////////////
stage.addEventListener(Event.ENTER_FRAME, gameLoop)
theAcc.addEventListener(AccelerometerEvent.UPDATE, onAcc);
function onAcc(e:AccelerometerEvent):void{
mcPlayer.x -= (e.accelerationX * 65);
}
/////////////////////////////////////////////////
////////////Fire Missile onTouch/////////////////
////////////////////////////////////////////////
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
function onTouch(event:TouchEvent):void
{
////////////////
//fire missile//
////////////////
fireMissile();
}
function fireMissile():void
{
//////////////////////
//create new missile//
//////////////////////
var newMissile:mcMissile = new mcMissile();
///////////////////////////////////
//add missile object to the stage//
///////////////////////////////////
stage.addChild(newMissile);
////////////////////////////////////////////////
//position our missile object on top of player//
////////////////////////////////////////////////
newMissile.x = mcPlayer.x;
newMissile.y = mcPlayer.y;
/////////////////////////////
//add our new missile array//
/////////////////////////////
aMissileArray.push(newMissile);
trace(aMissileArray.length);
}
}
private function gameLoop(e:Event):void{
clampPlayerToStage();
}
/////////////////////////////////////////////
//If our player is to the Left of The Stage//
/////////////////////////////////////////////
private function clampPlayerToStage():void{
if(mcPlayer.x < mcPlayer.width/2)
{
mcPlayer.x = mcPlayer.width/2;
}
//////////////////////////////////////////////
//If our Player is to the Right of the Stage//
//////////////////////////////////////////////
if(mcPlayer.x > stage.stageWidth - (mcPlayer.width/2))
{
mcPlayer.x = stage.stageWidth - (mcPlayer.width/2);
}
}
}