Hi There,
I’m currently working on a game where every “Step” - defined by a global time modifier - everything on screen calculates where it’s next position will be, then uses tweenlite to animate itself to that location.
This program runs for about 10 seconds before it eats 100% of my CPU. iMac i5 quad core, so it’s not the hardware.
The problem is specifically in the following snippet, and the peculiar thing is if I teleport everything to it’s next position (i.e. don’t tween it there) the CPU is stable at 6% (where flash IDE consumes 4%). Does anyone know why these tweens are just stacking and stacking and never garbage collecting ? (This is what I assume the problem is, as I can’t find another explanation as to why the problem only exists when i TWEEN to the next location)
Thanks very much in advance.
public function animateEntities():void
{
var i;
for (i = 0; i < _currentEntities.length; i++) {
if (_currentEntities*.moving == true) {
var deltaX = _currentEntities*.nextX - _currentEntities*.xLocation;
var deltaY = _currentEntities*.nextY - _currentEntities*.yLocation;
TweenLite.to(_currentEntities*,1 / _currentSpeed,{x:_currentEntities*.x + (deltaX * 35),y:_currentEntities*.y - (deltaY * 35),ease:Linear.easeNone,overwrite:2,onComplete:dispatchComplete});
if (_currentEntities*.nameField == "Ship" || _currentEntities*.nameField == "Alien") {
_currentEntities*.turnCount = 0;
}
if (_currentEntities*.nameField == "Alien") {
//trace(_currentEntities*.nextX + ", " + _currentEntities*.nextY);
}
}
}
}
public function dispatchComplete():void
{
var i;
for (i = 0; i < _currentEntities.length; i++) {
var deltaX = _currentEntities*.nextX - _currentEntities*.xLocation;
var deltaY = _currentEntities*.nextY - _currentEntities*.yLocation;
_currentEntities*.xLocation = _currentEntities*.xLocation + deltaX;
_currentEntities*.yLocation = _currentEntities*.yLocation + deltaY;
if (_currentEntities*.redirect == true) {
_currentEntities*.objectDirection = _currentEntities*.nextDir;
_currentEntities*.redirect = false;
}
}
var finished = new interactionEvent("finishStep",true);
dispatchEvent(finished);
}