# problem with animation time and setFrame

**URL:** <https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406>\
**Category:** TexturePacker\
**Created:** [January 17, 2022, 9:03pm UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406 "2022-01-17T21:03:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![e.sobole](https://forums.solar2d.com/user_avatar/forums.solar2d.com/e.sobole/32/2087_2.png) [@e.sobole](https://forums.solar2d.com/u/e.sobole)\
**Post date:** [January 17, 2022, 9:03pm UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/1 "2022-01-17T21:03:25Z")

</div>

Hi I bought texturePacker and I trying it !

For some strange reason I can set a time param to slow down the animation  
I can use SetFrame too.

But I can’t use both together 😬 !

```
local sheetInfo = require("star")
local myImageSheet = graphics.newImageSheet( "star.png", sheetInfo:getSheet() )
local sprite = display.newSprite(myImageSheet, {{frames={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, time=1000}});
sprite:setFrame(3)
sprite:play()

```

Here is the code.  
The setFrame call stop the animation !

If I remove time = 1000 then it works !

---

<div class="post-metadata">

**Author:** ![depilz](https://forums.solar2d.com/user_avatar/forums.solar2d.com/depilz/32/143_2.png) [@depilz](https://forums.solar2d.com/u/depilz)\
**Post date:** [January 18, 2022, 12:34am UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/2 "2022-01-18T00:34:40Z")

</div>

It’s because the animation is playing only once, you need to specify that you want it to play indefinetively with the ` loopCount` parameter set to 0:

```lua
local sprite = display.newSprite(myImageSheet, {{
   frames = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 
   time = 1000,
   loopCount = 0
}})

```

And then everything else stills the same.

---

<div class="post-metadata">

**Author:** ![e.sobole](https://forums.solar2d.com/user_avatar/forums.solar2d.com/e.sobole/32/2087_2.png) [@e.sobole](https://forums.solar2d.com/u/e.sobole)\
**Post date:** [January 18, 2022, 11:12am UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/3 "2022-01-18T11:12:22Z")

</div>

Hum.

Unfortunately that’s not it !

But I think it must be something like that. A missing parameter!  
Until now without optimizing the textures, the use of the 2 parameters simultaneously was possible. It is therefore in the way texturePacker creates the imageSheet that there is a problem!

I’ve put the archive here, if someone want to try.

[https://www.hillgreen.app/tmp/coin.zip](https://www.hillgreen.app/tmp/coin.zip)

There must be a simple solution to the problem because I don’t think I’m the first to use texturePacker 😄

---

<div class="post-metadata">

**Author:** ![cyberparkstudios](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/c/a6a055/32.png) [@cyberparkstudios](https://forums.solar2d.com/u/cyberparkstudios)\
**Post date:** [January 18, 2022, 2:17pm UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/4 "2022-01-18T14:17:01Z")

</div>

This fixes it …

local frame  
local coinModule = require(‘texturePack.coin’)  
local tCoinBank = graphics.newImageSheet(‘texturePack/coin.png’, coinModule:getSheet());  
local coin = display.newSprite(tCoinBank, {start=1, count=30, time = 1000, loopCount = 0 });  
coin.x = 100  
coin.y = 100

```
frame = coinModule:getFrameIndex(Coin_00010)    
coin:setFrame(frame)
coin:play()
```

---

<div class="post-metadata">

**Author:** ![e.sobole](https://forums.solar2d.com/user_avatar/forums.solar2d.com/e.sobole/32/2087_2.png) [@e.sobole](https://forums.solar2d.com/u/e.sobole)\
**Post date:** [January 18, 2022, 3:48pm UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/5 "2022-01-18T15:48:37Z")

</div>

> [@cyberparkstudios](#):
>
> `frame = coinModule:getFrameIndex(Coin_00010) `

No !  
coinModule:getFrameIndex(Coin\_00010) return nil and it’s works but do not start at frame 10

coinModule:getFrameIndex(‘Coin\_00010’) return 10 but this this it doens’t works.

---

<div class="post-metadata">

**Author:** ![cyberparkstudios](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/c/a6a055/32.png) [@cyberparkstudios](https://forums.solar2d.com/u/cyberparkstudios)\
**Post date:** [January 18, 2022, 4:53pm UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/6 "2022-01-18T16:53:59Z")

</div>

Sorry, I only tested it to see if it would freeze up when setting frame as in your description of the problem. Never checked to see what the actual frame value was.

check out this link, it might be helpful

> **[Simplifying sprites and image sheets in Corona SDK](http://bitstopixels.blogspot.com/2016/10/simplifying-sprites-and-image-sheets-in.html)**
>
> An indie developer's thoughts on full-stack mobile app and game development using Corona SDK, React Native and anything related.

---

<div class="post-metadata">

**Author:** ![cyberparkstudios](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/c/a6a055/32.png) [@cyberparkstudios](https://forums.solar2d.com/u/cyberparkstudios)\
**Post date:** [January 18, 2022, 5:29pm UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/7 "2022-01-18T17:29:41Z")

</div>

maybe try this : this did work on my computer

local coinModule = require(‘texturePack.coin’)  
local tCoinBank = graphics.newImageSheet(‘texturePack/coin.png’, coinModule:getSheet());  
local sheet = coinModule:getSheet()  
local seqData = sheet.sequenceData  
local coin = display.newSprite(tCoinBank, seqData)  
coin.x = 100  
coin.y = 100  
coin:setSequence(“ten”)  
coin:play()

in your coin.lua add sequenceDtaa table just below the sheetContentHeight

be sure to put a comma after sheetContentHeight then drop in this …

sequenceData =  
{  
{  
name = “one”,   
start = 1,  
time = 1000,  
count = 30,  
loopCount = 0,  
},  
{  
name = “ten”,   
frames = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,  
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3,  
4, 5, 6, 7, 8, 9},   
time = 1000,  
loopCount = 0,  
}  
},

you of course can add more sequenceData tables to your liking

---

<div class="post-metadata">

**Author:** ![e.sobole](https://forums.solar2d.com/user_avatar/forums.solar2d.com/e.sobole/32/2087_2.png) [@e.sobole](https://forums.solar2d.com/u/e.sobole)\
**Post date:** [January 18, 2022, 6:03pm UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/8 "2022-01-18T18:03:46Z")

</div>

Hum. Yes.

That’s a nice solution !

Better still would be that the bug is fixed, but I note your solution 👍!  
It’s probably better than rewriting an animation management system 🙂

Thank you !

---

<div class="post-metadata">

**Author:** ![cyberparkstudios](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/c/a6a055/32.png) [@cyberparkstudios](https://forums.solar2d.com/u/cyberparkstudios)\
**Post date:** [January 18, 2022, 6:06pm UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/9 "2022-01-18T18:06:58Z")

</div>

good luck with your app!

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [January 19, 2022, 12:24am UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/10 "2022-01-19T00:24:58Z")

</div>

> [@e.sobole](#):
>
> The setFrame call stop the animation !

Of course it does. It has nothing to do with texturepacker.

You literally just told the framework to show a specific frame and stop the animation!

[https://docs.coronalabs.com/api/type/SpriteObject/setFrame.html](https://docs.coronalabs.com/api/type/SpriteObject/setFrame.html)

If you mean “start at frame 10” then you need to define a sequence.

---

<div class="post-metadata">

**Author:** ![e.sobole](https://forums.solar2d.com/user_avatar/forums.solar2d.com/e.sobole/32/2087_2.png) [@e.sobole](https://forums.solar2d.com/u/e.sobole)\
**Post date:** [January 19, 2022, 9:39am UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/11 "2022-01-19T09:39:55Z")

</div>

Hi SGS

I have tried with sequence

```
local coinModule = require('texturePack.coin')
local tCoinBank = graphics.newImageSheet('texturePack/coin.png', coinModule:getSheet());
local sequences = {{ name = 'test', start=1, count=30, time = 1000, loopCount = 0 }}
local coin = display.newSprite(tCoinBank, sequences)
coin:setSequence('test')
coin.x = 100
coin.y = 100
coin:setFrame(10)
coin:play()

```

Same thing ! That doesn’t works.  
I’m pretty sure there is a default sequence if you don’t specify one, which is why it doesn’t change anything!

---

<div class="post-metadata">

**Author:** ![bgmadclown](https://forums.solar2d.com/user_avatar/forums.solar2d.com/bgmadclown/32/490_2.png) [@bgmadclown](https://forums.solar2d.com/u/bgmadclown)\
**Post date:** [January 20, 2022, 2:46am UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/12 "2022-01-20T02:46:28Z")

</div>

I’d suggest using existing methods that works with this one. I’m not sure if this is a bug in the framework but changing the way it works could cause some unforeseen troubles with the existing projects. If defining different sequences solves the problem, you should go with it.

---

<div class="post-metadata">

**Author:** ![system](https://forums.solar2d.com/uploads/default/original/1X/1bf6a947166df24e92aaa3358558f4b82d7f3d5a.png) [@system](https://forums.solar2d.com/u/system)\
**Post date:** [July 19, 2022, 2:46am UTC](https://forums.solar2d.com/t/problem-with-animation-time-and-setframe/354406/13 "2022-07-19T02:46:52Z")

</div>

Closed on July 19, 2022, 2:46am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
