cocos2d-objc icon indicating copy to clipboard operation
cocos2d-objc copied to clipboard

Frame animations from sprite sheets produce jerky animations...

Open iMobCoding opened this issue 11 years ago • 11 comments
trafficstars

This was sometimes a problem even in v2 cocos, but it was fixable by disabling rotated frames inside sheets or sometimes with POT textures. This problems still occurs with Sprite Builder too. So you import frames into sprite builder, you create sprite sheet and make animation. Inside sprite builder animation is good, but as soon as you play it in xcode project, animations is jerky...

iMobCoding avatar Jul 18 '14 01:07 iMobCoding

The problem in 3.0 and 2.x was the texture coordinate varying was a mediump variable. For POT textures over 1024x1024 in size, the variable was no long precise enough to represent exact pixels. For non-POT textures, you lose any real hope of aligning with texture pixels coordinates exactly.

3.1 changed the precision to highp during the renderer rewrite to fix the issue.

slembcke avatar Jul 18 '14 16:07 slembcke

But I am having this issue in v3.1. Even simple things like 2 button states aren't working with sprite sheets in v3.1. For example, I have button_normal.png and button_pressed.png with the same size. If I create sprite sheet and those pngs happen to be rotated there, then there is a visible position change when you touch and release a button...

iMobCoding avatar Jul 18 '14 16:07 iMobCoding

Really? Crud. I had made a couple simple tests for the precision issue anyway. Maybe this really is related to the rotation then.

slembcke avatar Jul 18 '14 16:07 slembcke

If you can't easily re-create the issue, I'll make a test case and post it here...

iMobCoding avatar Jul 18 '14 16:07 iMobCoding

Here is a video showing the issue: https://dl.dropboxusercontent.com/u/5351290/ForSharing/ArfArf.mp4 On the left are frames without sprite sheet, on the right are frames from the sprite sheet. Notice the jerky animation on the right.

Just to point, it's not related to the frame rotation inside the sheet, as you'll see that frames aren't rotated at all (attached image). Also here are sprite sheet files (plist & png) used in the video on the right (sheet is for standard iPhones, but same behavior is shown for retina iPhones and iPads on iOS 6 & 7): https://dl.dropboxusercontent.com/u/5351290/ForSharing/ArfArfSpriteSheet.zip dog As you'll see in the plist file, frames have correct sourceSizes (divisible by 2, even 4 & 8). So I don't think problem is in "mediump variable" but actually in wrong frames used for animations. Like code for adding frames doesn't use "real" sprite sizes, but "cropped" ones maybe, which vary in size from frame to frame?

iMobCoding avatar Jul 21 '14 16:07 iMobCoding

Same prob here. Did you find a fix? We surrounded the sprites with a frame to prevent transparency optimisation and it fixed the prob, so it's related to the way sprites are extracted and re-positionned.

BigPapoo avatar Aug 01 '14 14:08 BigPapoo

I finally got it. The culprit is the texture packer embedded in SpriteBuilder. I used to build my textures with TexturePacker that is much more powerful. I'm currently searching how to use TP in replacement of the embedded texture packer. Btw, in TP I chose to have all my sprites aligned on POT boundaries and that does the trick regarding the jerkyness you have. Hope this helps

BigPapoo avatar Aug 01 '14 18:08 BigPapoo

Yes good find. I already pointed that animations play correctly inside SprBuilder but that's probably because SprBuilder doesn't use sprite sheets internally for playing, even you selected it for export...

When you talk about TP fix, which method you choose for that - "force word aligned" or "common divisor"?

iMobCoding avatar Aug 01 '14 18:08 iMobCoding

I use "common divisor" 2x2. Btw, sprites are not aligned on POT boundaries but aligned on "multiple of two", but you rectified by yourself of course.

BigPapoo avatar Aug 01 '14 21:08 BigPapoo

I caught this issue on some Android devices and on all iOS devices. The only one solution helped me - it is to use "Size constraints : Power of 2" in TexturePacker.

vyarovyi avatar Jan 30 '15 22:01 vyarovyi

Is there a solution besides "Power of 2"? Because "Power of 2" is kind of waste on some textures.

youngzhou avatar Apr 20 '15 07:04 youngzhou