View Full Version : [AS2] Anybody want some fire?
DJRoberts
02-17-2010, 03:44 PM
I have recently been aksed for a decent looking fire effect and it seems to be a common request. . I thought I'd post it up if anyone wants to use it they can. .
asgrunt
02-19-2010, 09:38 AM
Hi,
looks great and I like it much - especially since it is done in a simple but efficient way without much fancy coding. There are some minor points that could be changed:
- the way Math.random() is called is wrong. Only the outdated global function random() needed an argument, Math.random() does not.
- inside the mc fireball a random number is multiplied by 1 - which doesn't change anything. So you can just delete it.
- at the same place you are calculating two times a random number while only one is needed.
- a time line with only one frame doesn't need any stop() function.
- you can shorten that whole if-thingy into:
var nMoving:Number;
var nMinusPlus: Number = 1;
then instead of if:
nMoving = Math.random()*(nMinusPlus *= -1);
this._x += nMoving;
Unfortunately, it makes it a bit more difficult to modify code if there are several scripts written at different places. Its much easier if everything is in just one frame at the main time line. Something like that would do (did use most of your code to make it easier):
var depth:Number = 0;
var nXPos:Number = Stage.width/2;
var nYPos:Number = Stage.height/2;
var mFire:MovieClip, mFirePlace:MovieClip;
this.attachMovie("Firegrate","firegrate",depth++,{_x:10+nXPos, _y:nYPos});
mFirePlace = this.createEmptyMovieClip("contFire", depth++);
this.attachMovie("front","front",depth++,{_x:10+nXPos, _y:nYPos});
function makeFire() {
mFire = mFirePlace.attachMovie("fireball", "fireball"+depth, depth++, {_x:(Math.random()*35)+nXPos, _y:-40+nYPos, _alpha:30, nMinusPlus:1});
mFire.onEnterFrame = function() {
this._alpha--;
this._xscale -= 6;
this._yscale -= 0.01;
this._y -= Math.random()*10;
this.nMoving = Math.random()*(this.nMinusPlus *= -1);
this._x += this.nMoving;
if (this._alpha<=0) {
this.removeMovieClip();
}
};
}
setInterval(makeFire,10);
Delete the code inside the time line of fireball and delete the instance of Fire at _root. To get a more manageable code, you should use vars or args defining the values of alpha, xscale and so on. Instead of many enterFrames one single enterFrame would be enough, if all instances of fireball were referenced in an array.
However, this is a very nice effect that could be well used for anims or games
DJRoberts
02-19-2010, 11:30 AM
Thanks for pointing out some real school boy errors. I wrote this a while ago - cn't believe I gave Math.random() a parameter. Once again thanks.
Here's a better version:
I think its good that the code isn't on the first frame because it allows you to simply drag an instance of 'fire' from the library. This makes it good for users who can't code.
TomMalufe
03-01-2010, 06:38 PM
I don't know why I did it... bored I guess. Anyways, I just made a AS3 version of this. It's exactly the same in just about every way, but in AS3.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.