gpt4 book ai didi

ios - objective-c : How to avoid a collision between two ball?

转载 作者:行者123 更新时间:2023-11-29 04:41:52 25 4
gpt4 key购买 nike

我是新来的,我应该编写一个有两个球的游戏,第一个球由用户控制,第二个球应该编程。不知道如何保证第二个球不让球落到用户手中?我是中间人。你能帮助我吗。我有一个代码要更改:`CGRect tableRect = self.view.bounds; CGRect 敌人矩形 = self.enemy.frame;

if (CGRectGetMinX(enemyRect)<CGRectGetMinX(tableRect) ||
CGRectGetMaxX(enemyRect)>CGRectGetMaxX(tableRect)) {
playerValue++;
playerlabel.text = [NSString stringWithFormat: @"%d", playerValue];
enemylabel.text = [NSString stringWithFormat: @"%d", enemyValue];
moveX = -moveX;

}
if (CGRectGetMinY(enemyRect)<CGRectGetMinY(tableRect) ||
CGRectGetMaxY(enemyRect)>CGRectGetMaxY(tableRect)) {
playerValue++;
playerlabel.text = [NSString stringWithFormat: @"%d", playerValue];
enemylabel.text = [NSString stringWithFormat: @"%d", enemyValue];
moveY = -moveY;
}
CGPoint center = enemy.center;
center.x += moveX;
center.y += moveY;
enemy.center = center;
[self performSelector:@selector(move) withObject:nil afterDelay:timerIntervale];


if (CGRectIntersectsRect(enemyRect, player.frame)) {
CGRect frame = [player frame];
frame.origin.x = 137.0f;
frame.origin.y = 326.0;
[player setFrame:frame];

CGRect frame2 = [enemy frame];
frame2.origin.x = 137.0f;
frame2.origin.y = 20.0;
[enemy setFrame:frame2];
enemyValue++;
playerlabel.text = [NSString stringWithFormat: @"%d", playerValue];
enemylabel.text = [NSString stringWithFormat: @"%d", enemyValue];

}`

我想知道我是否更改了代码或添加了行。非常感谢您对我的帮助。

添加游戏

最佳答案

enemy.userInteractionEnabled = NO;

关于ios - objective-c : How to avoid a collision between two ball?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10266583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com