SCNAction 动画

//
//  GameViewController.m
//  SCNAction
//
//  Created by 柯木超 on 2019/4/9.
//  Copyright © 2019年 柯木超. All rights reserved.
//

#import "GameViewController.h"

@implementation GameViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.scnView = [[SCNView alloc]initWithFrame:self.view.bounds];
    self.scnView.backgroundColor = [UIColor grayColor];
    
    [self.view addSubview: self.scnView];
    
    self.scnView.allowsCameraControl = YES;
    // 设置场景
    self.scnView.scene = [SCNScene scene];
    
    // 添加照相机
    SCNCamera *camera = [SCNCamera camera];
    
    // 设置正投影
    camera.usesOrthographicProjection = YES;
    // 设置正投影比例
    camera.orthographicScale = 10;
    
    SCNNode *caNode = [SCNNode node];
    caNode.camera = camera;
    caNode.position = SCNVector3Make(0, 0, 50);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:caNode];
    
    //添加两个正方体
    // 创建几何立体
    SCNBox *box1 = [SCNBox boxWithWidth:0.5 height:0.5 length:0.5 chamferRadius:0];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, 0, -20);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
    
    // 添加动画行为 沿着y轴旋转
    SCNAction *rotation = [SCNAction rotateByAngle:10 aroundAxis:SCNVector3Make(0, 1, 0) duration:2];
    
    SCNAction *moveUp = [SCNAction moveTo:SCNVector3Make(0, 5, 0) duration:1];
     SCNAction *moveDown = [SCNAction moveTo:SCNVector3Make(0, -5, 0) duration:1];
    
    //顺序执行动画
    SCNAction *sequence = [SCNAction sequence:@[moveUp,moveDown]];
    
    //组合动画之行
    SCNAction *group = [SCNAction group:@[sequence,rotation]];
    
    [node1 runAction:[SCNAction repeatActionForever:group]];
}

- (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

@end

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值