开发者

From iPhone to Mac

i've ben creating an iPhone game like theEagle1100 teaches in a YouTube tutorial.

But now I want to do the same 开发者_如何学Cfor Mac, and I'm real noob. My first problem is that I don't know how to get the ball move. For iPhone it worked like this:

ball.center = CGPointMake(ball.center.x + ballVelocity.x, ball.center.y + ballVelocity.y);

I can set the location of ball like this:

[ball setFrame:CGRectMake(144, 30, 32, 32)];

then I add the ballVelocity to the y value like this:

[ball setFrame:CGRectMake(144, 30 + ballVelocity.y, 32, 32)];

but now it adds it to 30. How can I add velocity to the current location of the ball so it could move????


Just like you did with ball.center.y, you just use the frame's origin instead of the center.

NSRect frame = [ball frame];
frame.origin.y += ballVelocity.y;
[ball setFrame:frame];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜