Warning max frame index

When I made an imagesheet animation with 35 sprites, I have this warnig.

WARNING: Sequence (Idle_R) has an invalid count (35) that makes the last frame index of the sequence (35) fall outside the range of valid image sheet frame indices: 1 <= index <= 15.

But in fact this is working.
All the 35 sprites are displayed.

What should I do with this Warning :thinking:

More often than not, that just means you’ve incorrectly defined the image sheet. I’ve used Solar2D for years and I still occasionally do this mistake when I manually set up image sheets. If you are using simple options, then double check that you are taking padding into account as that can quickly mess up your frame numbers.

Also, if everything is working correctly with your sprites regardless, then I’d double check that you aren’t accidentally creating a different sheet with different definitions elsewhere.

Hum.

In fact the problem is due to a very naughty code I’ve made.
In order to change animation when touch event, I made this (global variable is just for example) :

local hgSequence = {
	{ name="Anim1", start = 1, count = 15, time = 500},
	{ name="Anim2", start = 1, count = 8, time = 500},
}

local tmpSheet= graphics.newImageSheet("Anim1.png", {width = 128, height = 180, numFrames = 15})
_G.anim = display.newSprite(tmpSheet, hgSequence);
_G.anim.x = 150
_G.anim.y = 400
_G.anim:setSequence("Anim1");
_G.anim:play();

local btn = display.newCircle(display.contentCenterX, display.contentCenterY, 20)
function btn:touch(event)
	if event.phase == "began" then
		display.remove(_G.anim);
		local tmpSheet= graphics.newImageSheet("Anim2.png", {width = 128, height = 180, numFrames = 8})
		_G.anim = display.newSprite(tmpSheet, hgSequence);
		_G.anim.x = 150
		_G.anim.y = 400
		_G.anim:setSequence("Anim2");
		_G.anim:play();
	end
end
btn:addEventListener("touch", btn)

I remove the _G.anim of the display object list and when I creating it again, the warning occured, due to the different number of frame of the new animation !

Maybe I should create different newSprite object in different variable and use isVisible property to display the correct animation. It could be nicer :thinking:

In your initial post, the problem sequence is “Idle_R”, which isn’t even mentioned in the code above.

Also, you probably don’t want to be creating image sheets inside functions like that. You can just set them up once and use them wherever and whenever you need.

I change the name of file and variable to be more clear.

Finally I found a better way to do the same thing

local sheet1 = graphics.newImageSheet("Anim1.png", {width = 128, height = 180, numFrames = 15})
local sheet2 = graphics.newImageSheet("Anim2.png", {width = 128, height = 180, numFrames = 8})

_G.anim1 = display.newSprite(sheet1, {{ start = 1, count = 15, time = 500}});
_G.anim1.isVisible = false
_G.anim2 = display.newSprite(sheet2, {{ start = 1, count = 8, time = 500}});
_G.anim2.isVisible = false

_G.currentSprite = _G.anim1
_G.currentSprite.isVisible = true
_G.currentSprite.x = 150
_G.currentSprite.y = 400
_G.currentSprite:play();

local btn = display.newCircle(display.contentCenterX, display.contentCenterY, 20)
function btn:touch(event)
	if event.phase == "began" then
		_G.currentSprite.isVisible = false
		_G.currentSprite = _G.anim2
		_G.currentSprite.isVisible = true
		_G.currentSprite.x = 150
		_G.currentSprite.y = 400
		_G.currentSprite:play();
	end
end
btn:addEventListener("touch", btn)

No need to create a newSprite inside the event !
The only question is: When I set isVisible to false does the animation take any time to be handle !

I’m fairly sure that’s not the only question, but the answer is yes. Animations continue to run even if the display object is not visible. :stuck_out_tongue:

You need to explicitly stop the animations.

Nedd I just call pause() method ?

_G.currentSprite:pause()
_G.currentSprite.isVisible = false

Then

  • no display
  • no animation
  • no touch screen detection

It should not take a lot of time to the system.
I could have 100 animation in this state !

Thank You XeduR !

Like I guessed, and like it should be, it was just the “only question for now.” :stuck_out_tongue:

Yeah, just pausing the animation and then setting isVisible to false will do the trick. With touch, as long as you haven’t explicitly set the isHitTestable property to true, then you won’t be able to touch display objects when they aren’t visible.