actionscript physics stopper
Out of context: Reply #6
- Started
- Last post
- 12 Responses
- noneck0
onClipEvent(enterFrame) doesn't tax the server at all, unless you're doing a call to a script on it.
The taxation of a non-moving inertia script on a CPU is so small, it isn't even worth mentioning.
But that ain't really yer question, is it?
Most of the inertia scripts take the form of:
onClipEvent(enterFrame){
_x = (target._x - _x)/5;
}Which, as Boz kindly pointed out, won't ever really reach zero, but get very close. (Technically though, because flash automatically rounds to one decimal place, you would, eventually, reach zero. But I'm just being an ass now).
As my man neeko pointed out(sup, man?) the Math obejcts are only useful if you KNOW that you want to round up or down, so aren't as portable.
I would check to see if the difference between target._x and this._x are less than, say 1. If they are then this._x = target._x.
ie: it snaps into place if it's less than half a pixel out.
Let's put it together:
onClipEvent (enterFrame) {
//get pixels to move
movex = (target._x - _x)/5;//check if moving
//more than 1 pixel
if (1 < movex) {
_x = movex;
} else {
//moving less than 1 pixel
//snap in place
_x = target._x;
}
}But that's just how I'd do it. (Watch Colin Moock come along and show me stupid).
abizzyman is right, the friends of ed flash books are top notch. if you have the means, I'd highly suggest one. Though, I'd probably just go to the store and read them there, they suck as references.