ios - 生成其他节点后旋转停止
<p><p>猫正在产卵并跟随僵尸。它们也面向僵尸,但是当其他猫产卵时旋转停止。</p>
<pre><code>-(void)spawningCat
{
[self enumerateChildNodesWithName:@"cat" usingBlock:^(SKNode *node, BOOL *stop){
float actionDuration = 0.1;
CGPoint offset = CGPointSubtract(_zombie.position, node.position);
CGPoint direction = CGPointNormalize(offset);
CGPoint amountToMovePerSec = CGPointMultiplyScalar(direction, CAT_MOVE_POINTS_PER_SEC);
CGPoint amountToMove = CGPointMultiplyScalar(amountToMovePerSec, actionDuration);
node.position = CGPointMake(node.position.x+amountToMove.x, node.position.y+amountToMove.y);
_velocityCat = CGPointMultiplyScalar(direction, CAT_MOVE_POINTS_PER_SEC);
;
}];
}
-(void)spawnCat
{
_cat = ;
_cat.position = CGPointMake(ScalarRandomRange(0, self.size.width), ScalarRandomRange(0, self.size.height));
_cat.name = @"cat";
;
- (void)update:(NSTimeInterval)currentTime
{
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>只需使用 SKSpriteNode 对节点进行类型转换并旋转它。如下:</p>
<pre><code>[self enumerateChildNodesWithName:@"cat" usingBlock:^(SKNode *node, BOOL *stop){
SKSpriteNode *tempCat = (SKSpriteNode *) node; // typecast node
]; // eg: do action with 'tempCat' SKSpriteNode
}];
</code></pre>
<p>继续编码........ :)</p></p>
<p style="font-size: 20px;">关于ios - 生成其他节点后旋转停止,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25443141/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25443141/
</a>
</p>
页:
[1]