AS3颗粒爆炸



我来自AS2,在转换到AS3时遇到问题。我正试图用电影剪辑制作一个爆炸粒子,但一直遇到错误。

这是原始的AS2脚本:

maxparticles = 200; //number of particles
i = 0; //counter, for "while" loop
while(i < maxparticles){
newparticlename = "particle" + i; //creates a new name for a new particle instance
particle.duplicateMovieClip(newparticlename, i); //duplicates our particle mc
i++;
}

这是我转换后的AS3脚本:

var maxparticles = 200; //number of particles
var i = 0; //counter, for "while" loop
while(i < maxparticles){
var newparticlename = "particle" + i; //creates a new name for a new particle instance
particle.duplicateMovieClip(newparticlename, i); //duplicates our particle mc
i++;
}

我在这里一直遇到问题:

particle.duplicateMovieClip(newparticlename,i(;

非常感谢您的帮助。

AS3的做法有点不同。没有duplicateMovieClip这样的方法,也没有这样的概念AS3以更对象的方式操纵视觉对象(MovieClips、Shapes等(:您可以创建和销毁它们,可以将它们保存在内存中以备将来使用,还可以将它们从各自的父对象分离并重新连接到其他位置。

为了创建同一对象的多个实例,您需要执行以下操作:

  1. 将其创建为项目库中的MovieClip(而不是Graphic(项
  2. 在库属性中为其指定一个并命名该类,例如粒子。基类应为MovieClip(默认值(。我不能提供任何屏幕,但应该不难弄清楚
  3. 放置以下代码:

(请记住,它没有经过测试,但概念应该是正确的(

// Allows the script to interact with the Particle class.
import Particle;
// Number of particles.
var maxparticles:int = 200;
// I imagine you will need to access the particles somehow
// in order to manipulate them, you'd better put them into
// an Array to do so rather then address them by their names.
var Plist:Array = new Array;
// Counter, for "while" loop.
var i:int = 0;
// The loop.
while (i < maxparticles)
{
// Let's create a new particle.
// That's how it is done in AS3.
var P:Particle = new Particle;

// The unique name for the new particle. Whatever you want it for.
P.name = "particle" + i;

// Enlist the newly created particle.
Plist.push(P);

// At the moment, the P exists but is not yet attached to the display list
//  (or to anything). It's a new concept, there wasn't  such thing in AS2.
// Let's make it a part of the display list so that we can see it.
addChild(P);

i++;
}

相关内容

  • 没有找到相关文章

最新更新