SpriteSheet gets played several time while countLoop=1 ?

I have a spritesheet animation which i want to play only one loop, but instead it gets played 5 times before it ends. Imagesheet doesnt have repeated images. Here is my code, if anyone can help please :slight_smile:

function mysprite(x, y, xScale, yScale, start, count) local options={ width=202, height=202, numFrames=49, sheetContentWidth=2022, sheetContentHeight=1012, } local image\_sheet=graphics.newImageSheet("myanimation.png", options) local sprite=display.newSprite(image\_sheet, { name="once", start=start, count=count, time=10000, loopCount=1 }) sprite.x=x sprite.y=y sprite.xScale=xScale sprite.yScale=yScale sprite:play() return sprite end

Hi @blablu1212,

This basically looks OK, so I’m not sure why it’s repeating. What parameters (arguments) are you passing to this function?

Brent

hi @Brent

Here are the parameters passed.

Is there any way to stop the animation after is repeated only once?

local asprite=mysprite(250, 350, 0.75, 0.75, 1, 49) mygroup:insert(asprite)

Hi @blablu1212,

Can you try calling “sprite:play()” on the object that is returned from the function, in this case “asprite”?

And on a related note, you shouldn’t be creating a new image sheet every time this function is called. You should create the image sheet before you call the function, then pass its reference into the function.

Hope this helps,

Brent

Hi @Brent,

 Yeah i noticed the creation of imagesheet too, and i fixed it by creating sequesnces,

 so i just call :setSequence once spritesheet is created.

 Also tried asprite:play() and doesnt make any difference :frowning:

So you’re doing this basically?

  1. Create the image sheet, with a local reference.

  2. Call the “mysprite()” function, passing the image sheet reference to it as a parameter/argument.

  3. On the returned sprite object, call :play().

And the sprite continues to loop forever?

Correct :slight_smile:

Can you post your image sheet, assuming it’s not copyright-protected material or something? You could put a giant “watermark” on the image if so, such that it couldn’t be copied and used by anybody…

Can you share your email please? idk if i can share the image online?

You can post the image here if there’s no privacy issues. Click on the “More Reply Options” under the message submission box and you should see the fields to attach an image on the next page.

I would feel more comfortable if i share it on private :slight_smile:

Ok, it’s brent [at] coronalabs [dot] com.

@Brent, please let me know if you got my email?

Best Regards

Yes, I received it, thanks. It appears that the frames are not in the expected order. Remember that, by default, the animation will occur starting at the top-left frame, then proceed to the right (not down) across that row. When it reaches the end of the row, it will move to the left frame of the next row and proceed to the right. When it’s complete, the last frame will be the most bottom-right.

You can, of course, tell the animation to go in any specific order that you want, by specifying the frame index numbers and the order they should be animated in.

Brent

Thank you so much @Brent, that fixed the issue :slight_smile:

I tried by frames and also fixed the order that came automatically from texturepacker by choosing Algorithm:Basic

Best Regards

Hi @blablu1212,

This basically looks OK, so I’m not sure why it’s repeating. What parameters (arguments) are you passing to this function?

Brent

hi @Brent

Here are the parameters passed.

Is there any way to stop the animation after is repeated only once?

local asprite=mysprite(250, 350, 0.75, 0.75, 1, 49) mygroup:insert(asprite)

Hi @blablu1212,

Can you try calling “sprite:play()” on the object that is returned from the function, in this case “asprite”?

And on a related note, you shouldn’t be creating a new image sheet every time this function is called. You should create the image sheet before you call the function, then pass its reference into the function.

Hope this helps,

Brent

Hi @Brent,

 Yeah i noticed the creation of imagesheet too, and i fixed it by creating sequesnces,

 so i just call :setSequence once spritesheet is created.

 Also tried asprite:play() and doesnt make any difference :frowning:

So you’re doing this basically?

  1. Create the image sheet, with a local reference.

  2. Call the “mysprite()” function, passing the image sheet reference to it as a parameter/argument.

  3. On the returned sprite object, call :play().

And the sprite continues to loop forever?