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

  • #1, z dionousWednesday, 24. May 2017, 10:48 hodinky 7 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.

    Fanoušek fóra

    246 Posts


  • Kapitán

    1582 Posts

  • #3, z afrlmeWednesday, 24. May 2017, 11:26 hodinky 7 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

    Imperátor

    7285 Posts

  • #4, z dionousWednesday, 24. May 2017, 13:05 hodinky 7 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 

    Fanoušek fóra

    246 Posts

  • #5, z afrlmeWednesday, 24. May 2017, 13:28 hodinky 7 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)


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

    Imperátor

    7285 Posts

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

    Maybe something like this?
    This is a wild guess  grin

    Zabiják klíčů

    810 Posts

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

    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.

    Imperátor

    7285 Posts

  • #8, z ke4Wednesday, 24. May 2017, 13:33 hodinky 7 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.

    Zabiják klíčů

    810 Posts

  • #9, z dionousWednesday, 24. May 2017, 13:44 hodinky 7 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: 

    Fanoušek fóra

    246 Posts

  • #10, z SimonSWednesday, 24. May 2017, 13:51 hodinky 7 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"])

    Kapitán

    1582 Posts

  • #11, z dionousWednesday, 24. May 2017, 14:21 hodinky 7 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?

    Fanoušek fóra

    246 Posts