【问题标题】:Remove all created symbols from stage从舞台上删除所有创建的符号
【发布时间】:2015-04-09 05:57:39
【问题描述】:

我通常不这样做,但我在这里迷路了。

import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;

var first_tile:colors;
var second_tile:colors;
var pause_timer:Timer;
var game_timer:Timer;
var colordeck:Array = new Array(1,1,2,2,3,3,4,4,5,5,6,6);

function color_match() {
    game_timer = new Timer(10000,1);
    for (x=1; x<=4; x++) {
        for (y=1; y<=3; y++) {
            var random_card = Math.floor(Math.random()*colordeck.length);
            var tile:colors = new colors();
            tile.col = colordeck[random_card];
            colordeck.splice(random_card,1);
            tile.gotoAndStop(7);
            tile.x = ((x-1)*70)+30;
            tile.y = ((y-1)*100)+30;
            tile.addEventListener(MouseEvent.CLICK,tile_clicked);
            game_timer.addEventListener(TimerEvent.TIMER_COMPLETE,end_game);
            addChild(tile);
        }
    }
    game_timer.start();
}
function tile_clicked(event:MouseEvent) {
    var clicked:colors = (event.currentTarget as colors);
    if (first_tile == null) {
        first_tile = clicked;
        first_tile.gotoAndStop(clicked.col);
    }
    else if (second_tile == null && first_tile != clicked) {
        second_tile = clicked;
        second_tile.gotoAndStop(clicked.col);
        if (first_tile.col == second_tile.col) {
            pause_timer = new Timer(1000,1);
             pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);
            pause_timer.start();
        }
        else {
            pause_timer = new Timer(1000,1);
            pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);
            pause_timer.start();
        }
    }
}
function reset_tiles(event:TimerEvent) {
    first_tile.gotoAndStop(7);
    second_tile.gotoAndStop(7);
    first_tile = null;
    second_tile = null;
    pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);
}
function remove_tiles(event:TimerEvent) {
    removeChild(first_tile);
    removeChild(second_tile);
    first_tile = null;
    second_tile = null;
    pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);
}

function end_game(event:TimerEvent) {


}

这是一个小小的配色游戏。单击两个图块,如果匹配它们就会消失,否则会变回灰色。该循环以随机放置的对创建颜色实例,并将它们设置为第 7 帧(灰色)。

当游戏时间为零时,我不知道如何移除任何剩余的色块。我尝试的一切都在抛出错误。然后的想法是让人们再次玩,或者一个胜利脚本。

您不必为我编写代码,我只需要了解过程!谢谢。

【问题讨论】:

    标签: actionscript-3 flash flash-cs6


    【解决方案1】:

    我认为最好的方法是创建一个容器,这样您就可以添加所有图块并以您决定的最佳方式管理它们。

      var tileContainer:Sprite = new Sprite();
      addChild(tileContainer);
    
      // instead of addChild(tile);
      tileContainer.addChild(tile);
    
      // to remove all tiles
      tileContainer.removeChildren();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      • 1970-01-01
      • 2014-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多