我正在尝试制作一个随机类型的平台(基于我放置的精灵的形状),我的游戏主角将位于其中;如果敌人通过平台形状,它将被移除(就像它被倒下一样)。这是我想说的图片:
蓝点是英雄,红点是坏人;紫色圆圈内的那个是从圆形平台上掉下来应该去掉的那个
所以基本上,我不知道如何正确检测角色何时下降,我现在有一些东西,但是当整个身体都下降时它们会下降:
- (void) boundsCheck:(SKSpriteNode*)sprite{
CGPoint newPosition = self.position;
CGPoint newVelocity = self.velocity;
CGPoint bottomLeft = CGPointMake(sprite.frame.origin.x, sprite.frame.origin.y);
CGPoint topRight = CGPointMake(sprite.frame.origin.x + sprite.size.width,
sprite.frame.origin.y + sprite.size.height);
if (newPosition.x <= bottomLeft.x) {
[self removeCharacterWithPosition:newPosition];
}
if (newPosition.x >= topRight.x) {
[self removeCharacterWithPosition:newPosition];
}
if (newPosition.y <= bottomLeft.y) {
[self removeCharacterWithPosition:newPosition];
}
if (newPosition.y >= topRight.y) {
[self removeCharacterWithPosition:newPosition];
}
self.position = newPosition;
self.velocity = newVelocity;
}
你能告诉我一些提示吗?谢谢