ios - 将 Sprite 添加到其他 Sprite 位置
<p><p>我有两个 body </p>
<pre><code>SKShapeNode *hero = ;
hero.lineWidth = 1;
hero.fillColor = ;
hero.name = @"Hero";
hero.physicsBody = ;
hero.physicsBody.categoryBitMask = hero;
hero.physicsBody.collisionBitMask = friendlyCategory | enemyCategory;
hero.physicsBody.contactTestBitMask = friendlyCategory | enemyCategory;
hero.position = ;
SKShapeNode *circle = ;
circle.position = ;
circle.lineWidth = 2;
circle.strokeColor = ;
circle.fillColor = color;
circle.name = @"Circle";
circle.physicsBody = ;
circle.physicsBody.categoryBitMask = friendlyCategory;
circle.physicsBody.collisionBitMask = hero;
circle.physicsBody.contactTestBitMask = hero;
</code></pre>
<p>那么,</p>
<pre><code>- (void)didEndContact:(SKPhysicsContact *)contact
{
uint32_t collision = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask);
if (collision == (friendlyCategory | hero ))
{
SKShapeNode* node = (SKShapeNode*)contact.bodyA.node;
if ()
{
self.activeFriendlyBall = (SKShapeNode*)contact.bodyB.node;
}
else
{
self.activeFriendlyBall = (SKShapeNode*)contact.bodyA.node;
}
self.hero.position = self.activeFriendlyBall.position;
}
}
</code></pre>
<p>必须在 activeFriendlyBall 上方添加英雄,以使他处于中心位置。但它在他附近增加了。我认为是因为添加了物理体。但我需要使用物理 body 进行其他逻辑。</p>
<p> <a href="http://cl.ly/image/0g1S0d3h1h0w" rel="noreferrer noopener nofollow">http://cl.ly/image/0g1S0d3h1h0w</a> </p>
<p>必须是,如何在顶部屏幕中。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我找到了解决办法。</p>
<pre><code>self.heroBall.physicsBody.velocity = CGVectorMake(0, 0);
];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 将 Sprite 添加到其他 Sprite 位置,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32073030/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32073030/
</a>
</p>
页:
[1]