【发布时间】:2013-11-29 09:54:36
【问题描述】:
目标是让背景不断循环(横向滚动类型的游戏)。我在网上找到了一些代码,它可以在 Flash 的“操作”面板中运行,但是有人告诉我,我的“操作”面板中不能有任何内容,并且我的所有代码都必须在 ActionScript 文件 (.as) 中。有没有办法在 actionscript 文件中而不是在操作窗口中执行此代码?如何? - 非常感谢,我真的很感激!
//The speed of the scroll movement.
var scrollSpeed:uint = 2;
//This adds two instances of the movie clip onto the stage.
var s1:ScrollBg = new ScrollBg();
var s2:ScrollBg = new ScrollBg();
addChild(s1);
addChild(s2);
//This positions the second movieclip next to the first one.
s1.x = 0;
s2.x = s1.width;
//Adds an event listener to the stage.
stage.addEventListener(Event.ENTER_FRAME, moveScroll);
//This function moves both the images to left. If the first and second
//images goes pass the left stage boundary then it gets moved to
//the other side of the stage.
function moveScroll(e:Event):void{
s1.x -= scrollSpeed;
s2.x -= scrollSpeed;
if(s1.x < -s1.width){
s1.x = s1.width;
}else if(s2.x < -s2.width){
s2.x = s2.width;
}
}
【问题讨论】:
标签: actionscript-3 flash actionscript