精灵套件碰撞:忽略透明度? [英] sprite kit collisions: ignore transparency?
问题描述
我正在使用 Xcode 的 spritekit 构建游戏.它是一个平台游戏,现在它可以很好地与平坦的地面碎片一起使用.我想知道是否可以忽略碰撞的 png 中的透明度.也就是说,如果我有一个带有弯曲地板和透明填充槽的地面,我可以让玩家走曲线而不是覆盖整个物体的方形边界框吗?我能找到的唯一示例是在 Gamemaker GML 语言中,您可以进行精确"碰撞,这样图像中的空白区域就不会算作精灵的一部分.如有必要,我可以提供代码,但这似乎更像是一个概念性问题.提前致谢
I am building a game with Xcode's spritekit. Its a platform game and right now it functions well with flat ground pieces. I was wondering if it was possible to ignore transparency in the png for collisions. That is to say, If i have a ground piece with a curved floor and transparency filling the troughs, can i make the player walk the curves instead of a square bounding box covering the whole thing? The only example i can find is in the Gamemaker GML language, you can do "precise" collisions such that blank space in the images do not count as part of the sprite. I can supply code if necessary but this seems like more of a conceptual question. Thanks in advance
推荐答案
嘿,Apple 文档中提供了一个简单的解决方案.
Hey there's a easy solution for this provided in the Apple Documentation.
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
sprite.physicsBody = [SKPhysicsBody bodyWithTexture:sprite.texture size:sprite.texture.size];
这会在纹理的物理路径周围创建一个物理体.
This creates a physics body around the physical paths of the texture.
这篇关于精灵套件碰撞:忽略透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!