createAnimation()?

  • #20, by afrlmeFriday, 17. November 2017, 20:24 6 years ago
    If you try returning getSprites as it is then it will just return a table name/id. I think you have to iterate through it. Try using a for loop & printing the values with that.
    local spr = Animations["example"]:getSprites(VAnimationSprites)
    
    for i = 1, #spr do
     print(spr[1])
    end

    I know that's probably incorrect as I'm writing an example off the top of my head, but whatever.

    Imperator

    7278 Posts


  • #21, by rhavin grobertSaturday, 18. November 2017, 00:04 6 years ago
    Ok, I messed a litte bit and now i can dynamically create an animation – kind of :/

    function createAnimationObject(_scene, _name)
        return scene:create(VSceneObjects, _name)
    end
    
    function createAnimation(_aniObj, _name, _path)
        local ani = _aniObj:create(VObjectAnimations, name)
        ani:setValue(VAnimationSprites, { {path = _path} })
        startAnimation(ani)
        return getObject("ActiveAnimations[".._name.."]")
    end
    
    myAniObj = createAnimationObject(game.CurrentScene, "back")
    myAnimation = createAnimation(myAniObj, "tunnel", "Kulissen/UBahn/Tunnel0.jpg")
    

    The problem with that approach is now: after some seconds, that animation is gone. getObject("ActiveAnimations[".._name.."]") returns the correct animation for some time, until it then returns nothing and in the log I find the following entry:

    Can't find object "tunnel" in table "ActiveAnimations"

    Whats happening there? Is some garbage-collector unaware of create()? I checked this by not saving the object as in above code but by just saving its unique name in my table, and while my table entries stay the same (so its not my table getting gc'd), that name is after some seconds simply unknown to the ActiveAnimations-table.

    Newbie

    47 Posts

  • #22, by afrlmeSaturday, 18. November 2017, 00:26 6 years ago
    Only animations that are preloaded manually or currently playing on the screen are listed under the ActiveAnimations table. If an animation isn't playing or preloaded then it won't be listed & if the animation has finished playing & wasn't preloaded then it's automatically removed from the table as soon as it's done.

    Imperator

    7278 Posts

  • #23, by sebastianSaturday, 18. November 2017, 00:29 6 years ago
    i assume that there is only that one frame, right? It may gets created with the default frametime (20ms). Maybe you need to let it loop. In the editor its called "infinite" and is a checkbox. I cant see that infinite as a property in the animation, but you could test this when creating the animation

    ani:setValue(VAnimationNumberOfLoops, 0)

    The wiki mentions that "0" is for endless loop. Not sure if its enough because i see no field which enables it (maybe default is "-1").

    Thread Captain

    2346 Posts