Actionscript 3 专注游戏-瓷砖旋转
我有一个简单的专注游戏5x4块(我有一个符号(tile_movieclip)和11帧-10帧数字1-10和第11背景(衬衫卡)) 我想在第一次将是可见的数字,几秒钟后,瓷砖必须变成背景(第11帧)。在我的代码中,我首先看到了所有数字,在1秒的时间里,只有一个(右下角)磁贴。请帮忙 注意:查找//错误可能在此处我认为问题隐藏在那里,但我不确定 资料来源如下:Actionscript 3 专注游戏-瓷砖旋转,actionscript-3,Actionscript 3,我有一个简单的专注游戏5x4块(我有一个符号(tile_movieclip)和11帧-10帧数字1-10和第11背景(衬衫卡)) 我想在第一次将是可见的数字,几秒钟后,瓷砖必须变成背景(第11帧)。在我的代码中,我首先看到了所有数字,在1秒的时间里,只有一个(右下角)磁贴。请帮忙 注意:查找//错误可能在此处我认为问题隐藏在那里,但我不确定 资料来源如下: package { // importing classes import flash.events.Event; im
package {
// importing classes
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
// end of importing classes
public class Main extends Sprite {
private var pickedTiles:Array = new Array();
private const NUMBER_OF_TILES:uint=20;
private var pause_game:Timer;
private var canPick:Boolean=true;
private var tiles:Array = new Array();
private var tile:tile_movieclip;
private var i:uint = 0;
public function Main() {
// variables and constants
// no more NUMBER_OF_TILES here
const TILES_PER_ROW:uint=5;
// end of variables and constants
// tiles creation loop
for (i=0; i<NUMBER_OF_TILES; i++) {
tiles.push(Math.floor(i/2));
}
trace("My tiles: "+tiles);
// end of tiles creation loop
// shuffling loop
var swap,tmp:uint;
for (i=NUMBER_OF_TILES-1; i>0; i--) {
swap=Math.floor(Math.random()*i);
tmp=tiles[i];
tiles[i]=tiles[swap];
tiles[swap]=tmp;
}
trace("My shuffled tiles: "+tiles);
// end of shuffling loop
// tile placing loop
for (i=0; i<NUMBER_OF_TILES; i++) {
tile=new tile_movieclip();
addChild(tile);
tile.cardType=tiles[i];
tile.x=5+(tile.width+5)*(i%TILES_PER_ROW);
tile.y=5+(tile.height+5)*(Math.floor(i/TILES_PER_ROW));
tile.gotoAndStop(tiles[i]+1); // This shows all number at first
canPick = false;
tile.buttonMode=true;
tile.addEventListener(MouseEvent.CLICK,onTileClicked);
}
pause_game=new Timer(1000,1);
pause_game.start();
pause_game.addEventListener(TimerEvent.TIMER_COMPLETE,hideTiles);
}
// end of tile_placing_loop
//Error can be HERE!!!!!
private function hideTiles(e:TimerEvent) {
pause_game.removeEventListener(TimerEvent.TIMER_COMPLETE,hideTiles);
tile.gotoAndStop(NUMBER_OF_TILES/2+1); //This turns to background just one tile (the lower right corner)
canPick = true;
}
private function onTileClicked(e:MouseEvent) {
if(canPick){
var picked:tile_movieclip=e.currentTarget as tile_movieclip;
trace("you picked a "+e.currentTarget.cardType);
// checking if the current tile has already been picked
if (pickedTiles.indexOf(picked)==-1) {
pickedTiles.push(picked);
picked.gotoAndStop(picked.cardType+1);
}
// end checking if the current tile has already been picked
// checking if we picked 2 tiles
if (pickedTiles.length==2) {
canPick = false;
pause_game=new Timer(1000,1);
pause_game.start();
if (pickedTiles[0].cardType==pickedTiles[1].cardType) {
// tiles match!!
trace("tiles match!!!!");
pause_game.addEventListener(TimerEvent.TIMER_COMPLETE,removeTiles);
} else {
// tiles do not match
trace("tiles do not match");
pause_game.addEventListener(TimerEvent.TIMER_COMPLETE,resetTiles);
}
// no more pickedTiles = new Array();
}
// end checking if we picked 2 tiles
}
}
private function removeTiles(e:TimerEvent) {
pause_game.removeEventListener(TimerEvent.TIMER_COMPLETE,removeTiles);
pickedTiles[0].removeEventListener(MouseEvent.CLICK,onTileClicked);
pickedTiles[1].removeEventListener(MouseEvent.CLICK,onTileClicked);
removeChild(pickedTiles[0]);
removeChild(pickedTiles[1]);
pickedTiles = new Array();
canPick = true;
}
private function resetTiles(e:TimerEvent) {
pause_game.removeEventListener(TimerEvent.TIMER_COMPLETE,resetTiles);
pickedTiles[0].gotoAndStop(NUMBER_OF_TILES/2+1);
pickedTiles[1].gotoAndStop(NUMBER_OF_TILES/2+1);
pickedTiles = new Array();
canPick = true;
}
}
包{
//导入类
导入flash.events.Event;
导入flash.display.Sprite;
导入flash.events.MouseEvent;
导入flash.events.TimerEvent;
导入flash.utils.Timer;
//导入类的结束
公共类Main扩展了Sprite{
private-var-pickedTiles:Array=new-Array();
瓷砖的专用施工编号:uint=20;
私人游戏:定时器;
私有变量canPick:Boolean=true;
私有变量tiles:Array=newarray();
私人var瓷砖:瓷砖/电影唇;
私有变量i:uint=0;
公共功能Main(){
//变量和常量
//这里没有更多的\u块
每行的常数:uint=5;
//变量和常量结束
//瓷砖创建循环
对于(i=0;i0;i--){
swap=Math.floor(Math.random()*i);
tmp=瓷砖[i];
瓷砖[i]=瓷砖[swap];
瓷砖[交换]=tmp;
}
跟踪(“我的洗牌:+牌”);
//洗牌循环结束
//铺砖环
对于(i=0;i您有一个tile数组,而在侦听器中您引用的是单个tile的tile
。您需要交换添加到显示列表中的所有tile,为此,您可以使用以下结构:
for (var i:int=numChildren-1;i>=0;i--) {
var mc:DisplayObject=this.getChildAt(i);
var picked:tile_movieclip=mc as tile_movieclip;
if (picked) picked.gotoAndStop(NUMBER_OF_TILES/2+1); // now, show the back
}
这将替换tile.gotoAndStop(tile的数量/2+1)隐藏项
函数中的
语句。您有一个tile数组,而在侦听器中,您引用的是单个tile,即tile。您需要交换添加到显示列表中的所有tile,为此,您可以使用以下结构:
for (var i:int=numChildren-1;i>=0;i--) {
var mc:DisplayObject=this.getChildAt(i);
var picked:tile_movieclip=mc as tile_movieclip;
if (picked) picked.gotoAndStop(NUMBER_OF_TILES/2+1); // now, show the back
}
这将替换tile.gotoAndStop(tile的数量/2+1)
函数中的语句。
这不是字面意义上的错误。可能这段代码不正确,或者它位于错误的位置。或者我遗漏了什么。这不是字面意义上的错误。可能这段代码不正确,或者它位于错误的位置。或者我遗漏了什么。Vesper-smokebass@mail.r作为一个职业职业者,他是作为一个职业职业职业者,作为作为作为一个职业职业者,作为作为作为一个职业职业者,作为作为作为作为一个职业者的职业者,作为作为作为作为作为作为作为作为作为作为作为作为作为作为一个职业者的职业者,作为作为作为一个职业者,作为作为作为作为作为作为一个职业者,作为作为作为作为作为作为作为作为作为一个职业者,作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为的的的的的的的职业的的的的的的的的的的的的的,作为作为作为作为жжааааааааа,ааа维斯珀-smokebass@mail.ru-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙-摩加迪沙作为一个研究者,作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为作为чччаааааа。чааао, напишу тебе.