Dienstag, 29. November 2016

Animate UVs / Animate Texture for a SpriteAtlas / Flipbook effekt

let spriteatlasanimation = CAKeyframeAnimation()
        
// We do not directly animate UV´s but a matrix instead that moves the
// UV´s across the texture space
spriteatlasanimation.keyPath = "geometry.firstMaterial.diffuse.contentsTransform"

let pos0 = SCNMatrix4MakeTranslation(0.0, 0.0, 0)
let pos1 = SCNMatrix4MakeTranslation(0.1, 0.1, 0)
let pos2 = SCNMatrix4MakeTranslation(0.2, 0.2, 0)
let pos3 = SCNMatrix4MakeTranslation(0.3, 0.3, 0)
let pos4 = SCNMatrix4MakeTranslation(0.4, 0.4, 0)
let pos5 = SCNMatrix4MakeTranslation(0.5, 0.5, 0)
let pos6 = SCNMatrix4MakeTranslation(0.6, 0.6, 0)
let pos7 = SCNMatrix4MakeTranslation(0.7, 0.7, 0)
let pos8 = SCNMatrix4MakeTranslation(0.8, 0.8, 0)
let pos9 = SCNMatrix4MakeTranslation(0.9, 0.9, 0)

spriteatlasanimation.values   =  [pos0, pos1, pos2, pos3,  pos4,  pos5,  pos6,  pos7,  pos8,  pos9]
spriteatlasanimation.keyTimes =  [0, 0.10.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
spriteatlasanimation.duration0.5
spriteatlasanimation.isAdditive = false
        
// No Interpolation required for Flipbook effect : kCAAnimationDiscrete
spriteatlasanimation.calculationMode = kCAAnimationDiscrete
spriteatlasanimation.repeatCount = .infinity


<SCNNODE>.addAnimation(spriteatlasanimation, forKey: "test3")

Keine Kommentare:

Kommentar veröffentlichen