开发者

xcode animation ball iphone problem landscape mode

Hi everyone I'm french so scuse me for my english. My problem is that I'm animating a ba开发者_如何学JAVAll on the screen in portrait mode, but now I want do to the same thing in landscape mode. Everything work but when the ball hit a side of the iphone it go throught it. this code doesn't work I think that the problem is about x and y.

if (ball1.center.x > 480 ||ball1.center.x < 0){ ajout.x = -ajout.x; } if (ball1.center.y > 320 ||ball1.center.y < 0){ ajout.y = -ajout.y;


Yes your problem is with the x and y. In portrait mode that is correct with x being 480 and y being 320. However in landscape the two values are reversed.

Try this code instead;

CGRect _frame = [[UIScreen mainScreen] bounds];   

if (ball1.center.x > _frame.size.width || ball1.center.x < 0)
    ajout.x = -ajout.x;

if (ball1.center.y > _frame.size.height || ball1.center.y < 0)
    ajout.y = -ajout.y;

This should return the propery bounds of your screen (320x480 in portrait, 480x320 in landscape) and check against those values.

Cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜