OStack程序员社区-中国程序员成长平台

标题: ios - 生成其他节点后旋转停止 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 01:02
标题: ios - 生成其他节点后旋转停止

猫正在产卵并跟随僵尸。它们也面向僵尸,但是当其他猫产卵时旋转停止。

-(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);

        [self rotateNode:_cat toFace:_velocityCat rotateRadiansPerSec:CAT_ROTATE_RADIANS_PER_SEC];
    }];
}

-(void)spawnCat
{
    _cat = [SKSpriteNode spriteNodeWithImageNamed"cat"];
    _cat.position = CGPointMake(ScalarRandomRange(0, self.size.width), ScalarRandomRange(0, self.size.height));
    _cat.name = @"cat";
    [self addChild:_cat];

- (void)updateNSTimeInterval)currentTime
{
    [self spawningCat];
}



Best Answer-推荐答案


只需使用 SKSpriteNode 对节点进行类型转换并旋转它。如下:

[self enumerateChildNodesWithName"cat" usingBlock:^(SKNode *node, BOOL *stop){
    SKSpriteNode *tempCat = (SKSpriteNode *) node; // typecast node
    [tempCat runAction:[SKAction rotateByAngle:1 duration:1]]; // eg: do action with 'tempCat' SKSpriteNode
}];

继续编码........

关于ios - 生成其他节点后旋转停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25443141/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4