johnatm / itween

Automatically exported from code.google.com/p/itween
1 stars 2 forks source link

Stop utlilities should be simplified to re-use current methods #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
iTween's initial enhanced stop utilities (stop(), stopAll(),
stopChildren()) are sloppy.  Recode them to utilize internal dispose
methods and piggyback their development on lesser complex versions (i.e.
stopChildren() should call stop())

Original issue reported on code.google.com by pixelplacement on 17 May 2010 at 3:13

GoogleCodeExporter commented 8 years ago
Done. 

Solution:
//stop all iTweens in GameObject:
static function stop(target : GameObject) : void{
    var tweens = target.GetComponents(iTween);
    for (var tween : iTween in tweens) {
        tween.tweenDispose();
    }
}

//stop all iTweens in GameObject of type:
static function stop(target : GameObject, type : String) : void{
    var tweens = target.GetComponents(iTween);
    for (var tween : iTween in tweens) {
        var targetType : String = tween.type+tween.method;
        targetType = targetType.Substring(0,type.length);
        if(targetType==type.ToLower()){
            tween.tweenDispose();
        }
    }
}

//stop all iTweens in GameObject and children:
static function stopChildren(target : GameObject) : void{
    stop(target);
    for (var  child : Transform in target.transform) {
        stopChildren(child.gameObject);
    }
}

//stop all iTweens in GameObject and children of type:
static function stopChildren(target : GameObject, type : String) : void{
    stop(target,type);
    for (var  child : Transform in target.transform) {
        stopChildren(child.gameObject,type);
    }
}

//stop all iTweens in scene:
static function stopAll() : void{
    for(var i : int=0; i<tweens.length; i++){
        var currentTween : Hashtable = tweens[i];
        var target : GameObject = currentTween["target"];
        var script : iTween = target.GetComponent(iTween);
        script.disableKinematic();
        Destroy(script);
    }
    tweens.Clear();
}

//stop all iTweens in scene of type:
static function stopAll(type : String) : void{
    var removeArray : Array = [];
    var i : int;
    var target : GameObject;
    for(i=0; i<tweens.length; i++){
        var currentTween : Hashtable = tweens[i];
        target  = currentTween["target"];
        var targetType : String = (currentTween["type"] as String) +
(currentTween["method"] as String);
        if(targetType == type.ToLower()){
            removeArray.Push(target);
        }
    }
    for(i=0; i<removeArray.length; i++){
        target = removeArray[i];
        var script : iTween = target.GetComponent(iTween);
        script.tweenDispose();
    }
}

Original comment by pixelplacement on 17 May 2010 at 3:15