I followed a tutorial to make a 'dodge' style game. I've adapted mine so that when the moving images are bumped by another image, they animate and move in another direction.
My problem is that if I bump the image beyond the boundaries they get get 'stuck' of screen...
Any advice on how I can fix this problem?
Thanks
Matt
Here is the part of my code that 'should' keep the images within the screen... what am i doing wrong?
And then obviously the same for all the other ones.
__________________ PicBoard - a visual support app for children with autism, communication difficulties or learning difficulties. Available now for iPad.
TalkBoard - Adds Communication Aid features to PicBoard, for non-verbal children or adults. Available now for iPad.
I think it is my rotating animation command that gets the images stuck off screen (once they've passed the boundaries) the rotate animation seems to override the boundary??? Any advice on this
Here is my animation code:
Code:
//animation - spin the thing if hit
[UIButton beginAnimations:nil context:NULL];
[UIButton setAnimationDuration:1.5];
q1.transform = CGAffineTransformMakeRotation(3.054326191);
q1.transform = CGAffineTransformIdentity;
[UIButton commitAnimations];
//end animation
if something else is updating the .center positions, you could end up getting stuck. for example, if the x position is too far to one side, then reversing direction might not be enough to put it back inside the boundary. in this case, the boundary check would continue to fail every frame, causing it to reverse direction back and forth constantly.
try something like this:
Code:
if (q1.center.x > 320) {
q1.center.x = 320;
pos4.x = -pos4.x;
}
if (q1.center.x < 0) {
q1.center.x = 0;
pos4.x = -pos4.x;
}
// etc for q1.center.y, q2...
__________________ PicBoard - a visual support app for children with autism, communication difficulties or learning difficulties. Available now for iPad.
TalkBoard - Adds Communication Aid features to PicBoard, for non-verbal children or adults. Available now for iPad.