在EaselJS中访问事件目标

时间:2014-05-31 09:40:46

标签: javascript jquery easeljs

我是EaselJS的新手。我正在运行0.7.1版本。我有一个生成瓷砖的简单游戏。我想在点击它们时删除这些图块。我知道每个点击事件都会调用我的点击处理程序,但我的图块不会被删除。我做错了什么?

c99.Game = (function() {
    function Count99Game(){
        this.canvas = document.getElementById('game-canvas');

        this.stage = new createjs.Stage(this.canvas);
        var totalTiles = 10;

        for(var i = totalTiles; i>0; i--){
            var tile = new c99.Tile(i);
            this.stage.addChild(tile);

            tile.x = Math.random()*(this.canvas.width - tile.width);
            tile.y = Math.random()*(this.canvas.height - tile.height);

            tile.addEventListener("click", function(event){
                alert("Clicked");
                this.stage.removeChild(event.target);
                this.stage.update();
            }.bind(this));
        }       

        this.stage.update();
    }    
    return Count99Game;
})();

0 个答案:

没有答案