Reputation: 12549
I've just started iOS drawing programming and I found out that the coordinate system is different from Mac OS X, basically the point of origin on iOS is on the top left instead of the bottom left as on the mac. Just wondering if anyone knows why Apple made this change, and will it change on the future for Mac as well? I also saw on the docs that the coordinate system on iOS cannot be flipped, so I need to rewrite the code?
Upvotes: 2
Views: 2955
Reputation: 1990
I found an easy way to fix this. Instead of using a standard CALayer object as your base layer, create your own class (based on CALayer) that has a single call:
- (void)layoutSublayers;
{
for(sprite* aSprite in self.sublayers)
{
// -(y pos -1) flips the coordinate system to start in the lower left
aSprite.position = CGPointMake(aSprite.actualPosition.x, -(aSprite.actualPosition.y - 1.0));
}
}
sprite is just a CALayer class with an added CGPoint property, actualPosition. Update that value to move the sprite.
Upvotes: 1
Reputation: 3113
You are correct about the coordinate system. The reason, if I recall correctly, is that most platforms' drawing systems use upper-left as the coordinate origin. Mac OS X used lower-left because that's what NeXT used.
It probably won't change on the Mac in the future because then everyone would have to totally rewrite their drawing code.
Upvotes: 2