-1

我有 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班

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;
        }
    }   
}   
}

这是屏幕截图

http://img268.imageshack.us/img268/9250/1p0a.jpg

4

1 回答 1

0

您可以在实际添加 Boss 对象的位置发布代码吗?看起来像你的

Boss.scaleX = -1

这可以解释翻转的 x 轴

但是如果没有看到将老板添加到 main 的代码,我无法确定。

于 2013-10-15T04:14:17.620 回答