I’m so irritated right now

I never could have imagined that my biggest enemy at converting RummyFight to iOS would be the upside down coordinate system in Cocos2D. It might sound trivial that things are drawn from the bottom to the top instead of the top to the bottom but imagine this:

On Android, I created a pretty neat solution for the listboxes in the Lobby and in the NewFight-sections. To be able to swipe several objects up and down at the same time they were all attached to an invisible surface which the swipes moved up and down making all the attached objects to move up and down too.

This was made possible by having the invisible surface grow and shrink according to the number of items that were on the list. If there was 20 fights, then the surface was 20*ItemHeight high with fight #1 attached at the surface’s 0,0*ItemHeight. Fight #2 was attached at 0,1*ItemHeight etc. Since the surface grew at the bottom when a new fight was attached, it was easy to calculate the positions of the fight items.

Now since Cocos2D’s coordinate system grows upwards I must attach fight #1 to 0,SurfaceHeight. Fight #2 to 0,SurfaceHeight-1*ItemHeight etc. Now this sounds easy enough. Just a matter of adding one more variable to the equation.

But what happens when I grow the surface after I have added fights to it? The new space is created ABOVE the first fight instead of at the bottom, meaning that I must reposition the surface and also reposition all items on it… everytime the surface’s height have changed and this happens a lot.

And it looks like shit. Everything is jumping around since all items are pushed down at first, then pulled up again when I reposition them.

It seems I must think in a totally different way now. I need to look at this from another angle.
Maybe if the coordinate system is backwards, I must think backwards too.

Why oh why did the authors of Cocos2D choose an inverted coordinate system compared to how the screen is built? I seriously hope they had a VERY good reason for it because it’s driving me nuts!

0 Responses to “I’m so irritated right now”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: