Quote:
Originally Posted by Psevertson
I am having trouble. I have a shooting game app, that uses CGRectintersect. When you miss, the image grows, using this:
CGAffineTransform transform = CGAffineTransformMakeScale(1.2, 1.2);
image.transform = transform;
It works perfectly, but it only works once. I want the image to grow every time you miss. How would I do that?
Thanks!
|
You are setting the transform of your image to 1.2. That tells the system to draw it at 120% of its normal size. If you do it again, you aren't changing anything. You want it to be 120% bigger than it's previous size, which would be done like this:
Code:
image.transform = CGAffineTransformScale(image.transform, 1.2, 1.2);
That code multiplies the previous transform by a scale of 1.2, 1.2.
So, you'll get scales like this:
before after
100% 120%
120% 144%
144% 173%
173% 207%
207% 249%
249% 299%
299% 358%
Note that this will cause the scale to rise geometrically. It will start getting bigger much faster after a few times. Note how on the last change I listed, the scale jumped by almost 60% in one step.
If you want the size to go up linearly by 20% each step, put a scale value in an instance variable. Start it at 1.0 (100%) Each time you want to grow your object, add .2 to your scale value, and then use code like this:
Code:
scale += 0.2;
CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale);
image.transform = transform;