所以我得到了两个SKSpriteNodes,一个人类和一个街区。如果人类击中了顶部的方块,它应该能够跳,如果他在空中,他不应该。我使用的是intersectsNode,但是人类只跳在块的末尾,我真的不知道为什么。论坛的一位成员告诉我要使用bodyAtPoint,但是如果我使用它,它只显示:“SKSpriteNode声明选择器bodyAtPoint没有可见的@接口”。
我使用intersectsNode的当前代码:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
Human.physicsBody.velocity = CGVectorMake(0, 0);
if([Human intersectsNode:Block1]){
[Human.physicsBody applyImpulse:CGVectorMake(0, 40)];
}
发布于 2014-04-13 15:26:28
我建议您使用didBeginContact:
而不是intersectsNode
。在MyScene中,您可以这样设置它:
@implementation MyScene
{
BOOL playerBlockContact
}
- (void)didBeginContact:(SKPhysicsContact *)contact
{
uint32_t collision = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask);
if (collision == (CNPhysicsCategoryPlayer | CNPhysicsCategoryBlock))
{
playerBlockContact = true;
NSLog(@"Contact");
}
}
- (void)didEndContact:(SKPhysicsContact *)contact
{
uint32_t collision = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask);
if (collision == (CNPhysicsCategoryPlayer | CNPhysicsCategoryBlock))
{
playerBlockContact = false;
NSLog(@"Contact lost");
}
}
然后将您的if([Human intersectsNode:Block1])
替换为If(playerBlockContact)
。
https://stackoverflow.com/questions/23044223
复制相似问题