Actionscript 3 我需要让对象圆继续沿着屏幕向下重复,但我';我找不到正确的代码 导入flash.display.MovieClip; 导入flash.events.Event; 公共类电影{ 公共职能(){ //降雨 变量i:int; 对于(i=0;i祝好运! E.Talk.y+=1;尝试如果(E.Task.y> Point,StaleHead)E.Trase.y=0;,因此简短地查看条件。也考虑使用一个单帧监听器并循环通过显示列表(例如:为(var i:int=0;i < NoMeStudio;I++)/ < < /代码>)@GeorgeProfenza,我想你应该把它作为一个答案。 import flash.display.Sprite; import flash.display.Shape; import flash.display.DisplayObject; import flash.events.Event; package{ public class Rainfall extends Sprite {//class names should be title case private var numDrops = 50;//this make it easier to configure private var dropRadius = 20; private var maxY; public function Rainfall() { addEventListener(Event.ADDED_TO_STAGE,init);//make sure the stage property will not be null } private function init(event:Event):void{ maxY = stage.stageHeight;//getters can be slow, store the height so it can be reused for each drop reset var i:int; for (i = 0; i < numDrops; i++){ var mc:Shape = new Shape();//if no interactivity is needed, Shape is the simplest/lightest class to use for drawing mc.x = Math.random() * stage.stageWidth ; mc.y = Math.random() * 400 * 4 ; mc.alpha = 0.1 + Math.random() * 0.9;//alpha values are from 0 to 1. mc.graphics.beginFill(0x0000FF); mc.graphics.drawCircle(0,0,dropRadius); addChild(mc); } addEventListener(Event.ENTER_FRAME, moveDown) ; } private function moveDown(e:Event):void { //fall speed for(var i:int = 0 ; i < numDrops; i++){ var drop:DisplayObject = getChildAt(i); drop.y += 1 ; if(drop.y > maxY) drop.y = -dropRadius;//if the drop exits the screen downards, place it back at the top (above the visible area) } } } }
我对ActionScript3还相当陌生,但在想如何让圆圈在屏幕上连续循环时遇到了很多麻烦,但关于我做错了什么或我需要让它循环什么的任何提示都会抛出尝试以下方法:Actionscript 3 我需要让对象圆继续沿着屏幕向下重复,但我';我找不到正确的代码 导入flash.display.MovieClip; 导入flash.events.Event; 公共类电影{ 公共职能(){ //降雨 变量i:int; 对于(i=0;i祝好运! E.Talk.y+=1;尝试如果(E.Task.y> Point,StaleHead)E.Trase.y=0;,因此简短地查看条件。也考虑使用一个单帧监听器并循环通过显示列表(例如:为(var i:int=0;i < NoMeStudio;I++)/ < < /代码>)@GeorgeProfenza,我想你应该把它作为一个答案。 import flash.display.Sprite; import flash.display.Shape; import flash.display.DisplayObject; import flash.events.Event; package{ public class Rainfall extends Sprite {//class names should be title case private var numDrops = 50;//this make it easier to configure private var dropRadius = 20; private var maxY; public function Rainfall() { addEventListener(Event.ADDED_TO_STAGE,init);//make sure the stage property will not be null } private function init(event:Event):void{ maxY = stage.stageHeight;//getters can be slow, store the height so it can be reused for each drop reset var i:int; for (i = 0; i < numDrops; i++){ var mc:Shape = new Shape();//if no interactivity is needed, Shape is the simplest/lightest class to use for drawing mc.x = Math.random() * stage.stageWidth ; mc.y = Math.random() * 400 * 4 ; mc.alpha = 0.1 + Math.random() * 0.9;//alpha values are from 0 to 1. mc.graphics.beginFill(0x0000FF); mc.graphics.drawCircle(0,0,dropRadius); addChild(mc); } addEventListener(Event.ENTER_FRAME, moveDown) ; } private function moveDown(e:Event):void { //fall speed for(var i:int = 0 ; i < numDrops; i++){ var drop:DisplayObject = getChildAt(i); drop.y += 1 ; if(drop.y > maxY) drop.y = -dropRadius;//if the drop exits the screen downards, place it back at the top (above the visible area) } } } },actionscript-3,loops,Actionscript 3,Loops,我对ActionScript3还相当陌生,但在想如何让圆圈在屏幕上连续循环时遇到了很多麻烦,但关于我做错了什么或我需要让它循环什么的任何提示都会抛出尝试以下方法: import flash.display.MovieClip; import flash.events.Event; public class rainfall extends MovieClip { public function rainfall() { // rainfall
import flash.display.MovieClip;
import flash.events.Event;
public class rainfall extends MovieClip {
public function rainfall() {
// rainfall
var i:int;
for (i = 0; i< 50; i++)
{
//variables
var mc:MovieClip = new MovieClip ();
//theStage, and alpha properties
mc.x = Math.random() * stage.stageWidth ;
mc.y = Math.random() * 400 * 4 ;
mc.alpha = Math.random()* 2;
mc.graphics.beginFill(0x0000FF);
mc.graphics.drawCircle(0,0,20);
//trace
trace(i);
addChild(mc);
mc.addEventListener(Event.ENTER_FRAME, moveDown) ;
}
function moveDown(e:Event):void
{ //fall speed
e.target.y += 1 ;
}
}
导入flash.display.Sprite;
导入flash.display.Shape;
导入flash.display.DisplayObject;
导入flash.events.Event;
包装{
公共类Sprite{//类名称应为标题大小写
private var numDrops=50;//这使配置更容易
专用var dropRadius=20;
私有var-maxY;
公共职能(){
addEventListener(Event.ADDED_TO_STAGE,init);//确保STAGE属性不为null
}
私有函数init(事件:event):void{
maxY=stage.stageHeight;//getter可能很慢,请存储高度,以便在每次放置重置时重复使用
变量i:int;
对于(i=0;imaxY)drop.y=-dropRadius;//如果水滴向下退出屏幕,则将其放回顶部(可见区域上方)
}
}
}
}
它不是经过测试的代码,因此您可能会遇到语法错误,但这些想法已被注释:
您需要为您的问题使用一个条件:如果水滴的垂直位置大于舞台的高度,那么水滴的垂直位置应该重置回舞台的顶部(`if(drop.y>maxY)drop.y=-dropRadius;a)
虽然在刚开始使用flash时没有必要,但以下是一些有关使用flash时效率/速度的提示:
ADDED_TO_stage
事件<> P>祝好运! <代码> E.Talk.y+=1;尝试<代码>如果(E.Task.y> Point,StaleHead)E.Trase.y=0;,因此简短地查看条件。也考虑使用一个单帧监听器并循环通过显示列表(例如:<代码>为(var i:int=0;i < NoMeStudio;I++)/ < < /代码>)@GeorgeProfenza,我想你应该把它作为一个答案。
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.DisplayObject;
import flash.events.Event;
package{
public class Rainfall extends Sprite {//class names should be title case
private var numDrops = 50;//this make it easier to configure
private var dropRadius = 20;
private var maxY;
public function Rainfall() {
addEventListener(Event.ADDED_TO_STAGE,init);//make sure the stage property will not be null
}
private function init(event:Event):void{
maxY = stage.stageHeight;//getters can be slow, store the height so it can be reused for each drop reset
var i:int;
for (i = 0; i < numDrops; i++){
var mc:Shape = new Shape();//if no interactivity is needed, Shape is the simplest/lightest class to use for drawing
mc.x = Math.random() * stage.stageWidth ;
mc.y = Math.random() * 400 * 4 ;
mc.alpha = 0.1 + Math.random() * 0.9;//alpha values are from 0 to 1.
mc.graphics.beginFill(0x0000FF);
mc.graphics.drawCircle(0,0,dropRadius);
addChild(mc);
}
addEventListener(Event.ENTER_FRAME, moveDown) ;
}
private function moveDown(e:Event):void
{ //fall speed
for(var i:int = 0 ; i < numDrops; i++){
var drop:DisplayObject = getChildAt(i);
drop.y += 1 ;
if(drop.y > maxY) drop.y = -dropRadius;//if the drop exits the screen downards, place it back at the top (above the visible area)
}
}
}
}