【问题标题】:Killing Game Enemies ActionScript 3.0杀死游戏敌人 ActionScript 3.0
【发布时间】:2013-04-08 03:57:48
【问题描述】:

它们并不是真正的敌人,它们只是你射出的气球。但是,当他们使用 addChild 添加时,当我单击(拍摄)它们时,它们都没有播放它们的“死亡”动画。这是我的代码。如果它看起来杂乱无章,请原谅,我刚开始使用 ActionScript,之前没有 OOP 经验。

一切正常,除了点击孩子似乎根本没有注册到添加到舞台的对象。我没有外部类,我所有的实例名称都是正确的。我在链接中称气球为“受害者”。

import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.MouseEvent;


Mouse.hide();
cursor_mc.startDrag(true);


stage.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
shotHandler.addEventListener(MouseEvent.MOUSE_DOWN, boxShot);

function boxShot(evt:MouseEvent):void
{
    enemyBox.gotoAndStop(2);
}




    function onClick(event:MouseEvent):void

    {
        cursor_mc.play();
        var myBullet:MovieClip = new black_mc();
        myBullet.x = mouseX; myBullet.y = mouseY;
        stage.addChildAt(myBullet , 0);
    }


    var myTimer:Timer = new Timer(1200, 300);
    myTimer.addEventListener(TimerEvent.TIMER, createEnemies);
    myTimer.start();

    function createEnemies(e:Event):void
    {


        var circle:MovieClip = new victim();
        circle.x = Math.random() * stage.stageWidth;
        circle.y = Math.random() * stage.stageHeight;
        addChildAt(circle , 2);


    }

【问题讨论】:

    标签: flash actionscript game-development


    【解决方案1】:

    我查看了您的代码,但没有看到在您的“受害者”对象上添加了任何 MouseListeners。无论如何,如果你需要在点击对象时对它做一些事情,你可以这样写:

    function createEnemies(e:Event):void //your enemy creation function
    {
    
    
        var circle:MovieClip = new victim();
    
        circle.addEventListener(MouseEvent.CLICK, onObjClick); // here is your click listener
    
        circle.x = Math.random() * stage.stageWidth;
        circle.y = Math.random() * stage.stageHeight;
        addChildAt(circle , 2);
    
    
    }
    
    private function onObjClick(event:MouseEvent):void {
        var target:MovieClip = event.currentTarget as victim;
        target.gotoAndPlay("destroyAnim");
        //target.goToDeath();  uncomment this and comment previous line if you already have a destroy function into your "victim" class.
    }
    

    【讨论】:

      猜你喜欢
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多