-
11-17-2005, 06:33 PM
#341
curiouser and curiouser
thanks for sharing that - that's really useful to know!
-
11-18-2005, 12:40 PM
#342
Is their an event that makes it possible to have code run periodically but not every frame? (i use good old flash 6)
-
11-18-2005, 12:59 PM
#343
Senior Member
Originally Posted by helpmeplz
Is their an event that makes it possible to have code run periodically but not every frame? (i use good old flash 6)
You can always use counters to skip frames:
if(mycounter>10){
//run code
mycounter=0;
}
mycounter++;
or use getTimer() to run code after certain time:
if(mytime<getTimer()){
//run code
mytime=getTimer()+3000;
}
-
11-29-2005, 09:47 AM
#344
Originally Posted by helpmeplz
Is their an event that makes it possible to have code run periodically but not every frame? (i use good old flash 6)
I like to use the setInterval for those cases, you can choose every however many milliseconds you want it to run
If hunting is the sport of Kings than bowling is a fine sport as well - H.J.Simpson
-
04-27-2006, 02:19 PM
#345
Senior Member
Let's unearth this famous thread !
Anyone know how I could optimize this test ?
if (Math.abs(this._x-this._width/2-this._parent.progression[mc]._x+this._parent.progression[mc]._width/2)<this._parent.progression[mc].colli+this._width/2-3 and Math.abs(this._y-this._height/2-this._parent.progression[mc]._y+this._parent.progression[mc]._height/2)<this._parent.progression[mc].colli+this._height/2-3) {
It runs dozens (hundreds?) of time per frame in my code so it should be optimized as much as possible
Thanks in advance ^^
Last edited by fil_razorback; 04-27-2006 at 02:35 PM.
-
04-27-2006, 05:52 PM
#346
Senior Member
Firstly, nest the second statement within the first(otherwise it will test both, even if the first one fails, so put the second after the first with no and).
Secondly, if you save a variable of Math.abs, that may be faster.
code:
var _mathabs=Math.abs //Define only once, not every time looped through, so outside of loop
if (_mathabs(this._x-this._width/2-this._parent.progression[mc]._x+this._parent.progression[mc]._width/2)<this._parent.progression[mc].colli+this._width/2-3){
if(_mathabs(this._y-this._height/2-this._parent.progression[mc]._y+this._parent.progression[mc]._height/2)<this._parent.progression[mc].colli+this._height/2-3) {
//It is true
//Do stuff
}
}
That should help a bit.
(Also, you could save a reference to this every time in a local variable, though I don't know if that will help).
-
04-27-2006, 07:38 PM
#347
M.D.
you could aslo make a refrence to the _parent.progression[mc] so the script doesn't have to keep looking it up. If it were me i'd make all the variable names nice and small. I think that has a slight impact (if any)
code:
var abs = Math.abs
var ob = this._parent.progression[mc]
//properties, thanks unknownGuy
var w = this._width/2
var h = this._height/2
var obw = ob._width/2
var obh = ob._height/2
var colli = ob.colli
//main loop
onEnterFrame = function(){
//our variables
var x = this._x
var y = this._y
//ob's variables
var obx = ob._x
var oby = ob._y
//check
if(abs(x-w-obx+obw)<colli+w-3){
if(abs(y-h-oby+obh)<colli+h-3){
//do stuff
}
}
}
Last edited by mr_malee; 04-27-2006 at 08:16 PM.
-
04-27-2006, 08:13 PM
#348
Senior Member
I've never been sure of this, but Mr. Malee, for the obx, obw, oby, and obj, wouldn't it be faster not to create a local variable since it is only used once(since by creating the variable you are using it once + creating a variable)?
-
04-27-2006, 08:15 PM
#349
M.D.
whoops, yes it would, however you need to update the x and y positions
-
04-28-2006, 01:59 AM
#350
Senior Member
Thanks ! I'll nest the if statements and do a reference to this._parent.progression
I can't make a reference to Math.abs...It's not a constant value but an operation >_<
Anyway, many thanks to both of you
-
04-28-2006, 02:38 AM
#351
M.D.
why cant you reference Math.abs, are you using it as a function or something?
i do it all the time with Math.floor and Math.sqrt
chuck it on frame one of your main timeline as
_global.abs = Math.abs
-
04-28-2006, 10:15 AM
#352
Senior Member
O_o
I never tried such a thing. Would it be faster?
-
04-28-2006, 10:44 AM
#353
Hype over content...
Yes.
Just 'cause it's a built in method doesn't mean you can't create a short-cut to it ( I think this was covered in the first few pages of this thread ).
It's no different doing something like
var rnd=Math.random;
than
var health=playerSprite.health;
Squize.
-
04-28-2006, 02:02 PM
#354
Hey Timmy!!!
I'm sure this was explained earlier in the thread but I didn't see it. And I haven't looked thorugh all of it but here it is. I've noticed in the very beginning of this thread when you guys were talking about if/else statements. Now when you were talking about this I recall something of a ? statement and how it performs. I'm just wondering what this ? statement is or is just anykind of a statement after the if/else?
-
04-28-2006, 06:14 PM
#355
Senior Member
As far as I understood it works like this
code:
var myVar= Math.round(Math.random())+1;
var isMyVarEqualToTwo = "The Answer is : " + (myVar == 2 ?"true":"false");
Another question, about collision detection in Shumps...it it less slow to use
code:
everybullet.onEnterFrame = function(){
//test every ennemies with a for...in loop
}
OR
code:
onlyOneMovieClip.onEnterFrame=function(){
for(bullets in the game){
for(ennemies in the game){
//Do hitest
}
}
}
-
04-28-2006, 06:21 PM
#356
Senior Member
It is generally thought(I believe is true, haven't tested) that one onEnterFrame is the best.
-
05-09-2006, 03:13 AM
#357
Would I take a performance hit for breaking apart an imported bitmap, edit it, and then regrouping it?
The motivation behind the question is that I am trying find a quick way to break up the frames in a sprite sheet without using trace bitmap (which appears to be really slow). When I copy and paste from an external paint program, the transparency is not preserved, so I have to use break apart + lasso tool to remove the background.
I could preserve transparency by cutting each frame in the sprite sheet and saving them individually, but that is way too tedious.
Any help is appreciated, thanks much!
EDIT: I did some testing, and found that using a bitmap as is was about 3% faster than breaking it up.
I created 60 movieclips of either a bitmap or a broken up one and timed their move across the screen from x=0 to x=600.
Anyone seen similar results?
Last edited by drakz; 05-09-2006 at 05:19 AM.
-
05-09-2006, 07:03 AM
#358
Jee, sounds like my worst nightmare: breaking apart a bitmap then lasso to create an alpha for sprites: Ahhhhhh! get me out of here.
Well no! get yourself a real image editing program and save your stuff with transparency as gif or png24. I'll go for png24 because that gives you a smoth mask and then in Flash you can compress it as a Jpeg --> optimized as never!
If you cant aford photoshop of one of those, here are some free editing softs, which probably will do the job:
http://www.gimp.org
http://picasa.google.com
http://vicman.net/vcwphoto
http://www.cursorarts.com/ca_imffw.html
http://www.eecs.wsu.edu/paint.net
Hope nobody knows I am still on Flash 5
______________________________________
All artists are prepared to suffer for their work
but why are so few prepared to learn to draw?(Banksy)
-
05-09-2006, 08:23 AM
#359
Heli Attack!
Originally Posted by drakz
Would I take a performance hit for breaking apart an imported bitmap, edit it, and then regrouping it?
The motivation behind the question is that I am trying find a quick way to break up the frames in a sprite sheet without using trace bitmap (which appears to be really slow). When I copy and paste from an external paint program, the transparency is not preserved, so I have to use break apart + lasso tool to remove the background.
I could preserve transparency by cutting each frame in the sprite sheet and saving them individually, but that is way too tedious.
Any help is appreciated, thanks much!
EDIT: I did some testing, and found that using a bitmap as is was about 3% faster than breaking it up.
I created 60 movieclips of either a bitmap or a broken up one and timed their move across the screen from x=0 to x=600.
Anyone seen similar results?
Some tests were done a while back, using a lassoed alpha is actually faster than if the image has transparency. That said, it is an archaic method, and even though it offers minor speed increases, shouldn't be used.
Try using batch processing in photoshop (or use slices to export the images). If you have Flash 8, try using BitmapData to read from the bitmap instead of cutting it up.
-
05-09-2006, 08:36 AM
#360
Yes we can
breaking an image apart essentially makes it become a vector shape with a bitmap fill. If it then needs less or more performance than an image with alpha area depends on the amount of curves in the vector shape (so the more curves your "custom alpha mask" has,the more performance it will need).
As pred said its an archaic method,painful to do and a giant time waste.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|