简体   繁体   English

SpriteKit实体块

[英]SpriteKit Solid Block

I'm trying to make a solid platform/block where if the player lands on it, it just stands there. 我正在尝试制作一个坚固的平台/方块,如果玩家将其放在上面,它就会立在那里。 I have it using collisions, but it seems like there is an easier way. 我有使用碰撞的方法,但是似乎有一种更简单的方法。

What I'm going for is an effect where the player can "land" on the block, and not go through it. 我要寻找的是一种效果,玩家可以“降落”在积木上,而不经过积木。

 if (firstBody.categoryBitMask == playerCategory && secondBody.categoryBitMask == endPlatformCategory) {
    if (player.position.y > secondBody.node.position.y) {
        player.physicsBody.velocity = CGVectorMake(player.physicsBody.velocity.dx, abs(player.physicsBody.velocity.dy*.5));
    }
}

This code makes it fall back through after a few hits due to gravity, however. 但是,由于受到重力的影响,此代码使其无法通过。

If I understood you correctly, then try setting your player's physicsBody.collisionBitMask to interact with the block. 如果我对您的理解正确,请尝试将播放器的physicsBody.collisionBitMask设置为与该块进行交互。 Something like this: 像这样:

self.physicsBody.collisionBitMask = CNPhysicsCategoryBlock;

and the block's physicsBody.collisionBitMask to interact with the player. 以及该块的physicsBody.collisionBitMask与播放器进行交互。

self.physicsBody.collisionBitMask = CNPhysicsCategoryPlayer;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM