我有Cannon的课程,它可以转向玩家!!
package com.musuh {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.sampler.NewObjectSample;
import com.ply.Heli;
public class Cannon extends MovieClip {
public var enTarget:Heli;
public function Cannon(enTarget:Heli) {
this.enTarget = enTarget;
addEventListener(Event.ENTER_FRAME , update);
}
public function fire (m:MouseEvent){
trace("fire");
}
function update (e:Event) {
if (parent != null) {
var dx = enTarget.x - x ;
var dy = enTarget.y - y ;
var angle = Math.atan2(dy,dx)/Math.PI*180-90;
rotation = angle;
}
}
}
}
当我把它叫到主类时,它工作正常(它可以向玩家旋转)! ,但是当我在Boss类中调用它时(因为在我的游戏中这个boss可以至少有3个加农炮),这不是错误,而是错误地向玩家旋转..为什么会这样?
这是Boss Class
package com.musuh {
import flash.display.MovieClip;
import flash.events.Event;
import flash.utils.getTimer;
import com.peluru.bossBullet;
import com.ply.Heli;
import com.musuh.Cannon;
public class Boss extends MovieClip {
private var speedX:int = 6;
private var dx:Number; // speed and direction
public var bossHP:Number=20;
private var gun:Cannon;
public var hits:Array;
public var target:Heli;
public function Boss(target:Heli) {
this.target = target;
bossBullets = new Array();
hits = new Array(hit1,hit2,hit3,hit4,hit5,hit6);
addEventListener(Event.ADDED_TO_STAGE , onAddedToStage);
addEventListener(Event.ENTER_FRAME, movePlane)
addEventListener(Event.ENTER_FRAME, update)
}
private function onAddedToStage(event:Event):void
{
gun = new Cannon(target);
gun.x = 0;
gun.y = 200;
// add cannon to the MC Pitboss
addChild(gun);
}
public function movePlane(e:Event){
// move plane
this.x +=speedX;
{
speedX *= -1;
}
if (this.x <= 20)
{
speedX *= -1;
}
}
}
}
这是 SCREEN SHOOT
答案 0 :(得分:0)
你可以在实际添加Boss对象的地方发布代码吗?它看起来像你的
Boss.scaleX = -1
解释翻转的x轴
但是如果没有看到将你的老板添加到main的代码,我就无法确定。