Actionscript 3 对象类在';在movieclip类中调用(我的街机游戏)
我有加农炮的职业,它可以向玩家旋转Actionscript 3 对象类在';在movieclip类中调用(我的街机游戏),actionscript-3,flash,oop,actionscript,flash-cs5,Actionscript 3,Flash,Oop,Actionscript,Flash Cs5,我有加农炮的职业,它可以向玩家旋转 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 enTar
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门加农炮),它不是错误的,而是错误地向玩家旋转。。为什么会这样
这是老板班
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;
}
}
}
}
package com.musuh{
导入flash.display.MovieClip;
导入flash.events.Event;
导入flash.utils.getTimer;
进口com.peluru.bossBullet;
进口com.ply.Heli;
进口com.musuh.Cannon;
公共类Boss扩展MovieClip{
私有变量speedX:int=6;
私有变量dx:Number;//速度和方向
公共var BOSHP:编号=20;
私人火炮:加农炮;
公共变量:数组;
公共风险价值目标:合力;
公共职能主管(目标:Heli){
this.target=目标;
bossBullets=新数组();
hits=新阵列(hit1、hit2、hit3、hit4、hit5、hit6);
addEventListener(Event.ADDED_至_阶段,OnAddedStatage);
addEventListener(Event.ENTER_FRAME,movePlane)
addEventListener(Event.ENTER\u帧,更新)
}
AddedStatage上的私有函数(事件:事件):void
{
火炮=新加农炮(目标);
gun.x=0;
枪y=200;
//将加农炮添加到MC Pitboss
addChild(枪);
}
公共功能移动平面(e:事件){
//移动平面
这个.x+=speedX;
{
speedX*=-1;
}
如果(this.x你能在你实际添加Boss对象的地方发布代码吗?它看起来像你的
Boss.scaleX = -1
这就解释了x轴的翻转
但是,如果没有看到您将上司添加到main的代码,我无法确定。的可能重复。您应该编辑原始问题,而不是发布带有新详细信息的相同问题。