【发布时间】:2010-07-07 01:01:54
【问题描述】:
我正在开发的 2D 游戏似乎遇到了一个奇怪的问题。为了确定我的可玩角色精灵是否降落在平台上,我首先执行 if 语句检查 CGRectIntersectsRect 并且一旦我确定玩家精灵和平台精灵相交,然后我检查以确保中心点(加上一半玩家的高度)在平台上方,如果是,我将玩家的 'y' 速度设置为零。
playerVelocity.x=5;
playerVelocity.y+=gravity;
if (CGRectIntersectsRect([turtle getBounds], [platform getBounds])) {
if ([player getPosition].y>p.position.y+([player getBounds].size.height/2)) {
if (playerVelocity.y>0) {
playerVelocity.y=0;
inJump=NO;
}
}else {
inJump=YES;
}
}
[player setPosition:CGPointMake([player getPosition].x+playerVelocity.x, [player getPosition].y-playerVelocity.y)];
大多数情况下,此代码在游戏周期中有效,但时不时地,第二个“if 语句”被忽略,我的玩家精灵通过平台。我正在使用自定义精灵类在 OpenGL ES 1.1 中构建这个游戏。
任何对此问题的见解将不胜感激!
【问题讨论】:
-
[player getPosition]给你什么分数?左上方?中心?p.position呢? -
他们都给出了中心点。
标签: iphone collision-detection