gpt4 book ai didi

ios - 游戏 : ScoreNumber does not increase by 1. 每次加4(有时加10)

转载 作者:行者123 更新时间:2023-11-28 19:58:47 25 4
gpt4 key购买 nike

我有一款游戏,您可以在平台上弹跳。我希望每次在平台上弹跳时分数增加 1。但是,它每次都会增加一些随机数(比如 10)。

在 Game.h 中我有:

int ScoreNumber;
IBOutlet UILabel *ScoreLabel;
-(void)Score;

...

在 Game.m 中我有:

-(void)Score {
ScoreNumber = ScoreNumber +1.0;
ScoreLabel.text = [NSString stringWithFormat:@"%i", ScoreNumber];
}

-(void)PlatformMoving {
if (CGRectIntersectsRect(Bird.frame, Platform1.frame)) {
[self Score];
}
}
...

这应该每次都计数 1 但它计数大于 1

最佳答案

如果您在 (void)Score 方法中放置一个断点,您可能会看到它在每次反弹时被调用多次,因为矩形可能会重叠多个帧。您可以在 (void)PlatformMoving 方法中进行检查,以查看在再次调用 Score 之前最后一次测试是否失败。这将确保永远不会在连续 2 帧上调用 Score,并且应该防止每次弹跳得分超过一分。

关于ios - 游戏 : ScoreNumber does not increase by 1. 每次加4(有时加10),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25098803/

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