How to get widht,height of animated sprite?

SetColidRect doesn't work because w and h = 0 , why ?

local function createMeteorAnime(x, y)

    local tabMeteoriteAnime = {

    tmeteoriteAnime = math.random(#tabMeteoriteAnime)
    MeteorAnime = tabMeteoriteAnime[tmeteoriteAnime]

    if meteorAnimeCount < maxMeteoriteAnime then

        local meteoriteAnime =
        meteoriteAnime.imagetable ="images/".. MeteorAnime)
        meteoriteAnime.animation =, meteoriteAnime.imagetable, true)

        local w, h = meteoriteAnime:getSize()
        meteoriteAnime:setCollideRect(0, 0, w, h)
        local Xpath = math.random(400)
        local Ypath = -math.random(30) - h
        meteoriteAnime:moveTo(Xpath, Ypath)
        --meteoriteAnime:moveWithCollisions(Xpath, Ypath)

        print("witdh = "..w.." - height = "..h)

        meteorAnimeCount = meteorAnimeCount + 1

        function meteoriteAnime:collisionResponse(other)

            return gfx.sprite.kCollisionTypeOverlap



thank you for your advise

I don't really understand why you are setting meteoriteAnime.imagetable and meteoriteAnime.animation directly. There is nothing in the documentation that says this is possible. It seems by coincidence that setting the animator directly works, but you are supposed to set it using meteoriteAnime:setAnimator(). I don't think setting the imagetable directly does anything, you should set the image to the first frame of the animation using meteoriteAnime:setImage().


Unfortunately I failed to use the Animator() function.
I was able to solve my problem with:

local meteoriteAnimeSize = meteoriteAnime.imagetable:getImage(1)
local w, h = meteoriteAnimeSize:getSize()
meteoriteAnime:setCollideRect(0, 0, w -4 , h -4)

Bonne soirée.

You can read width and height properties from your sprite directly too. So sprite.width for example. There are also x and y properties you can read.