Monday, 9 April 2012

Don't rotate or scale your touchable Sprite in Cocos2D,

Got stuck with a bug for almost 2 weeks.

What happened was, I tried to rotate and scale down some sprites. Problem is, I found that all the touchable Sprites which used to work perfectly before the rotate and scale down won't respond to touches that were around top or bottom 15-20% area of the Sprite. That is, users now have to tap at the middle of the Sprite - which is very very very annoying.

After all sort of troubleshooting, I finally worked out it's because of the Sprites I am using. Unfortunately, been a developer who's not very good with designing and graphic :-(, plus a bit lazy (sometimes). To avoid the hassle of redrawing all the Sprites, I simply used the built-in Cocos2D function to rotate and scale down all the Sprites and that is where all the problem began. Looks like if you rotate or scale down your Sprites, somehow Cocos2D won't respond to touches on the top/bottom 15-20% of the Sprite. My test shows if I supplied extra set of properly rotated/scaled images, then everything works as expected - mystery solved! But what a pain as I now need another set of Sprite! ^%#%#@#$@%

Only if Cocos2D is smart enough to adjust all the touch function properly according to the scale/rotation been made to the Sprites, is this qualified to file it as a new bug, or is it a "known feature"?

Well the good news is, for those Sprites that are not touchable, you can still rotate/scale them as required.

No comments:

Post a Comment