大佬教程收集整理的这篇文章主要介绍了ios – Sprite工具包在移动父SKNode后找不到nodeAtPoint,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在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; }
以上是大佬教程为你收集整理的ios – Sprite工具包在移动父SKNode后找不到nodeAtPoint全部内容,希望文章能够帮你解决ios – Sprite工具包在移动父SKNode后找不到nodeAtPoint所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。