学生在做AS3,我使用FlashDevelop,我想跟随并使用本教程来帮助我创建塔防游戏:http://www.flashgametuts.com/tutorials/as3/how-to-create-a-tower-defense-game-in-as3-part-1/
我已经开始了一个新项目> ActionScript 3> ActionScript 3 Project和我所拥有的是Main.as,其中包含:
package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author Duncan John Bunting
*/
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
}
}
}
它提到将文件保存到source.fla文件所在的位置(我没有这个),就在第3块代码之前,它说"现在,我们必须返回到主.fla文件。创建一个新图层以放置操作,并添加以下代码:"
我如何在FlashDevelop中执行此操作,因为我没有source.fla?或者在FlashDevelop中是不可能的?
如果无法实现,有人可以指导我使用ActionScript3在FlashDevelop中创建游戏的教程。
感谢。
答案 0 :(得分:0)
是的,在FlashDevelop中,您无法访问.fla,但您仍然可以将时间轴代码移植到FlashDevelop中。为此,请将函数外部的所有var X:Y
语句放在行public function Main()
之上,而不管它们出现在何处。然后,将所有函数放在init()
函数声明的结尾之下。任何其他代码都应放入init()
。在您的情况下,该文件应如下所示:
package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author Duncan John Bunting
*/
public class Main extends Sprite
{
//setting vars to step in for turns and special blocks
var S:String = 'START';
var F:String = 'FINISH';
var U:String = 'UP';
var R:String = 'RIGHT';
var D:String = 'DOWN';
var L:String = 'LEFT';
var startDir:String;//the direction the enemies go when they enter
var finDir:String;//the direction the enemies go when they exit
var startCoord:int;//the coordinates of the beginning of the road
var lvlArray:Array = new Array();//this array will hold the formatting of the roads
//the names of these variables explain what they do
var currentLvl:int = 1;
var gameOver:Boolean = false;
var roadHolder:Sprite = new Sprite();//create an object that will hold all parts of the road
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
// stop(); MovieClip functions are not supported for Main
lvlArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,R,1,1,D,0,0,R,1,1,D,0,0,R,1,1,D,0,0,
0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,
0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,
S,D,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,R,1,F,
0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,
0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,
0,R,1,1,U,0,0,R,1,1,U,0,0,R,1,1,U,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
];
addChild(roadHolder);//add it to the stage
//run these functions at the start
makeRoad();
startGame();
}
function makeRoad():void{
var row:int = 0;//the current row we're working on
var block;//this will act as the block that we're placing down
for(var i:int=0;i<lvlArray.length;i++){//creating a loop that'll go through the level array
if(lvlArray[i] == 0){//if the current index is set to 0
block = new EmptyBlock();//create a gray empty block
block.graphics.beginFill(0x333333);
block.graphics.drawRect(0,0,25,25);
block.graphics.endFill();
addChild(block);
//and set the coordinates to be relative to the place in the array
block.x= (i-row*22)*25;
block.y = row*25;
} else if(lvlArray[i] == 1){//if there is supposed to be a row
//just add a box that will be a darker color and won't have any actions
block = new Shape();
block.graphics.beginFill(0x111111);
block.graphics.drawRect(0,0,25,25);
block.graphics.endFill();
block.x= (i-row*22)*25;
block.y = row*25;
roadHolder.addChild(block);//add it to the roadHolder
} else if(lvlArray[i] is String){//if it's a string, meaning a special block
//then create a special block
block = new DirectBlock(lvlArray[i],(i-row*22)*25,row*25);
addChild(block);
}
for(var c:int = 1;c<=16;c++){
if(i == c*22-1){
//if 22 columns have gone by, then we move onto the next row
row++;
}
}
}
}
function startGame():void{//we'll run this function every time a new level begins
//right now we don't have any code
}
}
}
当你被告知在你的.fla中画一些东西并为它指定名字时,会遇到更难的部分。这仍然可以移植到FD中,但是如果没有绘图,则必须使用扩展Sprite
(如果已分层)的类将所有绘制例程编码到FD中,或者Shape
(如果不是),并使用graphics
属性用于绘制简单的基元。请注意,您无法在FD中直接设置锚点,因此您的坐标应与预设锚点(0,0)对齐。