0
     private var previousClick = null;

        public static var floor1:Array = new Array();
                floor1[0] = [2,1,1,1,1,1,2];
                floor1[1] = [1,1,1,1,1,1,1];
                floor1[2] = [1,1,1,2,1,1,1];
                floor1[3] = [1,1,1,1,1,1,1];
                floor1[4] = [1,1,1,2,1,1,1];
                floor1[5] = [1,1,1,1,1,1,1];
                floor1[6] = [2,1,1,1,1,1,2];

        public function Main()
                {
                    var tilew:int = 60;
                    var tileh:int = 60;

                    for (var i:int=0; i<floor1.length; i++)
                    {
                        for (var u:int=0; u<floor1[i].length; u++)
                        {
                            var cell:MovieClip = new Tile();
                            cell.gotoAndStop(floor1[i][u]);
                            cell.x = ((u-i)*tileh)+365;
                            cell.y = ((u+i)*tileh/2)+70;
                            addChild(cell);

                            cell.addEventListener(MouseEvent.CLICK, mouseclick);
                        }
                    }

    function mouseclick(event:MouseEvent)
                {
                        (event.currentTarget as Tile).outline.gotoAndStop("active");
                        event.currentTarget.cellSelected = true;

                        event.currentTarget.removeEventListener(MouseEvent.CLICK,mouseclick);


                        if (previousClick !== null){
                             (previousClick as Tile).outline.gotoAndStop(1);
                             event.currentTarget.cellSelected = false;

previousClick.addEventListener(MouseEvent.CLICK,mouseclick);
                             trace(previousClick);
                        }
                        previousClick = event.currentTarget;
                        previousClick.cellSelected = true;
}

因此,我将称为单元格的瓷砖排列在一起以形成地板。当您单击一个单元格时,该图块的轮廓会发光,表明它当前已被选中。我还创建了一个布尔值,用于检查当前图块是否被选中。问题是,布尔值对我单击的不是当前选择的图块返回 true,尤其是我在游戏开始时单击的第一个图块。

所以我的问题是,我怎样才能获得一个我点击的、当前未被选择为不等于 true 的图块?

4

1 回答 1

0

我认为这是由重叠引起的。

你可以试试 cell.y = ((u+i)*tileh)+70;

于 2013-06-12T16:24:56.907 回答