Get the width (or height) of an animation frame with lua

  • #1, by atrusWednesday, 24. May 2017, 10:48 3 years ago
    Hello to all,

    Is there any way to get the width of a specific frame of an active animation with lua?

    We are creating some dynamic clouds based on the nice template here,

    but our cloud frames have different widths, so it would be nice to be able and get this width at every loop so we move them efficiently off the screen.

    Forum Fan

    237 Posts


  • Thread Captain

    1369 Posts

  • #3, by afrlmeWednesday, 24. May 2017, 11:26 3 years ago
    http://www.visionaire-studio.com/luadocs/#createsprite-path
    Look at that... more Lua features I didn't know about. You're doing a nice job with the Lua doc thing mate. wink

    Imperator

    6842 Posts

  • #4, by atrusWednesday, 24. May 2017, 13:05 3 years ago
    Thanks all, this is cool! Understand that one may choose between getAnimationSize() and createSprite()

    What would be the proper syntax for getAnimationSize?

    e.g.
    getAnimationSize(ActiveAnimations["cloud_1"]) wouldn't work i guess, we need to tell VS to get the specific frame 

    Forum Fan

    237 Posts

  • #5, by afrlmeWednesday, 24. May 2017, 13:28 3 years ago
    Thanks all, this is cool! Understand that one may choose between getAnimationInnerSize() and createSprite()

    What would be the proper syntax for getAnimationSize?

    e.g.
    getAnimationSize(ActiveAnimations["cloud_1"]) wouldn't work i guess, we need to tell VS to get the specific frame 
    maybe...
    local anim = ActiveAnimations["example"]:getAnimationSize()

    print(anim.x, anim.y)
    1
    2
    3


    getAnimationSize().x or getAnimationSize().y also possible if you only want to check width or height.

    Imperator

    6842 Posts

  • #6, by ke4Wednesday, 24. May 2017, 13:28 3 years ago
    getAnimationSize(ActiveAnimations["cloud_1"].CurrentSpriteIndex).x
    1

    Maybe something like this?
    This is a wild guess  grin

    Key Killer

    810 Posts

  • #7, by afrlmeWednesday, 24. May 2017, 13:30 3 years ago
    getAnimationSize(ActiveAnimations["cloud_1"].CurrentSpriteIndex).x
    1

    Maybe something like this?
    This is a wild guess  grin
    But then wouldn't you be better using the getSize() if you were going to be checking a specific sprite?

    As for which method is correct for accessing the size of an animation, I'm not sure. There wasn't an example on the document page that I could see.

    Imperator

    6842 Posts

  • #8, by ke4Wednesday, 24. May 2017, 13:33 3 years ago
    I have no idea mate, i guess he needs the width of the current frame of the active animation? You could check the width based on the current frame with the getSize() function i suppose.

    Based on the docs it should return the current frame sprite automatically i guess.
    "sprite rect for current sprite"

    @atrus: Well i guess you will have to try that and see.

    Key Killer

    810 Posts

  • #9, by atrusWednesday, 24. May 2017, 13:44 3 years ago
    i guess he needs the width of the current frame of the active animation
    that's correct

    well i can see that getAnimationSize(obj) needs an active anim as an argument, so i would go for ke4's solution also. but i tried both the above solutions with no success.

    In the logs i noticed this also:

    14:48:32.696:[string "(8,1154)"]:5: attempt to call global 'getAnimationSize' (a nil value)
    14:48:32.696:stack traceback:
     [C]: in function 'debugerror'
     [string "function debugfunc(err) debugerror(err) end"]:1: in function 'getAnimationSize'
     [string "(8,1154)"]:5: in main chunk
    14:48:32.696:Failed to run string in Lua: 

    Forum Fan

    237 Posts

  • #10, by SimonSWednesday, 24. May 2017, 13:51 3 years ago
    It's written in the docs which parameters it takes: obj TVisObj character, animation or activeanimation

    It takes the current sprite.

    I'll flesh it out:
    graphics.getAnimationSize(game.CurrentCharacter)
    graphics.getAnimationSize(Animations["animation"])
    graphics.getAnimationSize(ActiveAnimations["animation"])
    1
    2
    3

    Thread Captain

    1369 Posts

  • #11, by atrusWednesday, 24. May 2017, 14:21 3 years ago
    Now we are getting somewhere (missed the grapchics. part, duh) , thanks Simon!

    It seems it works, so i tried to print the result in the log file and i got this:

    table: 0x0fa23c10

    Is this correct? I suppose this is another format for the rectacle size?

    Forum Fan

    237 Posts

Write post