我对 SceneKit 和 SpriteKit 还是很陌生,刚刚开始制作一些 SCNNode 的动画。
我不明白什么时候使用 SCNAction 以及什么时候使用 CABasicAnimation。 SCNAction 和 CABasicAnimation 之间有什么性能差异吗?
最佳答案
要为 SceneKit 的内容制作动画,您至少可以使用四种方法:隐式动画、显式动画、 Action 和动态。让我们探索什么是什么。
观看 WWDC 2012 SceneKit Session 504 . 时间 28:40。
SCNAction是一个简单的、可重复使用的动画,它可以更改您附加到的任何节点的属性。您可以根据需要为每个对象使用任意数量的 SCNActions。将其视为许多复杂动画的最简单动画构建 block ,包含一个 3D 对象的多个 SCNAction。
let action = SCNAction.repeatForever(SCNAction.rotate(by: .pi,
around: SCNVector3(0, 1, 0),
duration: 3))
sphereNode.runAction(action)
You use actions most often to change the structure and content of the SCNNode object to which they are attached, but you can also use actions make other changes to the scene. In SceneKit, actions provide an easy way to implement animated behaviors that frequently change in response to user input.
SCNTransaction是一种用于创建隐式动画并将场景图更改组合为原子更新的机制。
@IBAction func fallAndFade(_ sender: Any) {
SCNTransaction.animationDuration = 3.0
sphereNode.position.y = -10
sphereNode.opacity = 0.25
}
或
SCNTransaction.begin()
SCNTransaction.animationDuration = 3
sphereNode.position.y = -10
sphereNode.opacity = 0.25
SCNTransaction.commit()
CAAnimation是 Core Animation 中显式动画的抽象父类(super class)。您可以使用表示几何动画的 CAAnimation 对象的属性来控制其时间、监视其进度,并为 SceneKit 附加操作以在动画期间触发。
let animation = CABasicAnimation(keyPath: "geometry.extrusionDepth")
animation.fromValue = 0.0
animation.toValue = 100.0
animation.duration = 1.0
animation.autoreverses = true
animation.repeatCount = .infinity
textNode.addAnimation(animation, forKey: "extrude")
CAAnimation provides the basic support for the CAMediaTiming and CAAction protocols. You do not create instance of CAAnimation: to animate Core Animation layers or SceneKit objects, create instances of the concrete subclasses CABasicAnimation, CAKeyframeAnimation, CAAnimationGroup, or CATransition.
Physics Simulation向场景元素添加动态行为,检测接触和碰撞,模拟重力、 Spring 和车辆等逼真的效果。
let node = SCNNode(geometry: SCNSphere(radius: 1.0))
scene.rootNode.addChildNode(node)
node.physicsBody = SCNPhysicsBody.dynamicBody()
scene.physicsWorld.gravity = SCNVector3(x: 0, y: -5, z: 0)
关于swift - SceneKit – SCNAction 和 CABasicAnimation 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53524443/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput
我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?
请帮助我理解范围运算符...和..之间的区别,作为Ruby中使用的“触发器”。这是PragmaticProgrammersguidetoRuby中的一个示例:a=(11..20).collect{|i|(i%4==0)..(i%3==0)?i:nil}返回:[nil,12,nil,nil,nil,16,17,18,nil,20]还有:a=(11..20).collect{|i|(i%4==0)...(i%3==0)?i:nil}返回:[nil,12,13,14,15,16,17,18,nil,20] 最佳答案 触发器(又名f/f)是