License from €75 Log in
DE EN FR ES IT CZ

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

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 10 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.
  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 10 years ago
  4. · 10 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

  5. · 10 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 
  6. · 10 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.
  7. · 10 years ago
    getAnimationSize(ActiveAnimations["cloud_1"].CurrentSpriteIndex).x

    Maybe something like this?
    This is a wild guess  grin
  8. · 10 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.

  9. · 10 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.
  10. · 10 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: 

  11. · 10 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"])
  12. · 10 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?

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?