This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorials:flipping_an_object [2011/03/11 17:47] – created daniel | tutorials:flipping_an_object [2013/03/05 10:19] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Flipping an object ====== | ||
+ | Sometimes, you need to flip an object horizontally or vertically. Sparrow' | ||
+ | |||
+ | Here's how to do it: | ||
+ | |||
+ | <code objc> | ||
+ | SPImage *image = [SPImage imageWithContentsOfFile: | ||
+ | image.scaleX = -1; // flip horizontally | ||
+ | [self addChild: | ||
+ | </ | ||
+ | |||
+ | The downside is that the bounds of the image move to the left with that approach. Think of the pin-analogy I used in [[manual: | ||
+ | |||
+ | To rectify this, you can simply move the image to the right by its width: | ||
+ | |||
+ | <code objc> | ||
+ | image.x += image.width; | ||
+ | </ | ||
+ | |||
+ | That works, but makes it a little difficult to move the object around. Alternatively, | ||
+ | |||
+ | <code objc> | ||
+ | SPImage *image = [SPImage imageWithContentsOfFile: | ||
+ | image.pivotX = image.width | ||
+ | image.pivotY = image.height / 2.0f; | ||
+ | image.scaleX = -1; | ||
+ | [self addChild: | ||
+ | </ | ||
+ | |||
+ | {{ : |