![]()
我在Sprite Kit中遇到了这个奇怪的问题.我正在使用nodeAtPoint和categoryBitMask来检测玩家在调用跳转方法时是否触地.
一切都在发挥作用.但是 – 为了在抽屉中显示一些可选按钮 – 当我使用SKAction moveto移动父节点时:CGPoint(我将地面和玩家都作为SKNode的子节点),玩家不会跳跃.我NSLog pointBelowPlayer,它和以前一样,但是blockNode.physicsBody是null!这可能是Sprite Kit中的一个错误,还是我遗漏了一些关于继承和位置的基本信息?
跳跃的方法:
-(voID)playerJump { // Player jump if on ground CGPoint pointBelowPlayer = CGPointMake(_player.position.x,_player.position.y-_player.size.height); SKNode *blockNode = [self nodeAtPoint:pointBelowPlayer]; if (blockNode.physicsBody.categoryBitMask == groundcategory){ [_player.physicsBody applyImpulse:CGVectorMake(0,120.0f)]; }} 移动父节点的方法:
-(voID)toggleDrawer { if (bDrawerVisible) { [_actionLayer runAction:[SKAction moveto:CGPointMake(0,0) duration:1]]; bDrawerVisible = false; } else { [_actionLayer runAction:[SKAction moveto:CGPointMake(0,200) duration:1]]; bDrawerVisible = true; }} 创建SpriteNodes:
-(ID)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { _actionLayer = [SKNode new]; _player = [self createPlayer]; [_actionLayer addChild:_player]; _ground = [self createGround]; [_actionLayer addChild:_ground];}-(SKSpriteNode *)createPlayer { SKSpriteNode *player = [SKSpriteNode spriteNodeWithImagenamed:@"redSquare.png"]; player.name = @"player"; player.scale = 0.5; player.position = CGPointMake(screenWIDth/3,player.size.height*2); player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:player.size]; player.physicsBody.categoryBitMask = playercategory; player.physicsBody.collisionBitMask = groundcategory; player.physicsBody.contactTestBitMask = notecategory; return player;}-(SKSpriteNode *)createGround { SKSpriteNode *ground = [SKSpriteNode spriteNodeWithImagenamed:@"ground.png"]; ground.name = @"ground"; ground.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:ground.size]; ground.physicsBody.dynamic = NO; ground.physicsBody.categoryBitMask = groundcategory; ground.physicsBody.collisionBitMask = playercategory; ground.xScale = screenWIDth/ground.size.wIDth;; ground.position = CGPointMake(self.size.wIDth/2,0); return ground;}解决方法 好的,我解决了这个问题…… 如果您有多个节点,则在您点击的位置上,如果最深节点没有名称或最深节点的名称,您将获得null.
所以使用它来遍历所有节点:
UItouch *touch = [touches anyObject];CGPoint location = [touch locationInNode:self];NSArray *buttonNodes = [self nodesAtPoint:location];for (SKNode *node in buttonNodes){ NSLog(@"%@",node.name);} 另外你可以使用NSLog(@“%f”,node.zposition);得到zposition看到女巫一个在上面.
总结以上是内存溢出为你收集整理的ios – Sprite工具包在移动父SKNode后找不到nodeAtPoint全部内容,希望文章能够帮你解决ios – Sprite工具包在移动父SKNode后找不到nodeAtPoint所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)