AnimationClip 有些属性动态赋值
您好, 我在使用Cocos creator 2.1.2 做一个游戏,
游戏里有一个Node, 我设计了一个动画, Angle, Opacity, Scale 等等属性可以静态值, 但是x, y 属性是不可以静态值, 必须运行时才获取实际x, y 值
(我的汉语不是那么好的, 这是我的英文表现: x, y property of the node in the AnimationClip can’t be static value, I can’t set actual value in design time, the x, y values of the property in this AnimationClip on this node is desided by another Node)
我找不到任何有关如何动态创建AnimationClip(不是AnimationClip.createWithSpriteFrames,因为此动画不是精灵帧序列动画的文档)以及如何在脚本中动态设置AnimationClip下的属性的文档。
(I can’t find any documentation about how to create AnimationClip dynamically (not AnimationClip.createWithSpriteFrames, because this animation is not sprite frame sequence animation.) and how to set properties under AnimationClip dynamically in script.)
我在运行时使用此代码强制设置AnimationClip的curveData属性,这对我有用,
(I force set curveData properties of AnimationClip when runtime using this code, It’s works for me,)
const nameOfAnimation = "FlyPokerCard"
const clip = this._animation.getClips().filter(item => item.name == nameOfAnimation)[0]
const position = clip.curveData.props
position.x[1].value = this.flyReferenceNode.x
position.y[1].value = this.flyReferenceNode.y
const user = GameGlobal.userInfo
if (this.owner != user.guid) {
position.scale[2].value.x = 0
position.scale[2].value.y = 0
}
else {
position.scale[2].value.x = 0.4
position.scale[2].value.y = 0.4
}
console.log((clip as any)._uuid)
this._animation.addClip(clip)
this._animation.play(nameOfAnimation)
但是游戏场景具有许多节点,并且在运行时具有不同的位置值,
(but game scene have many nodes and are have different location value at runtime,)
但是为什么是AnimationClip单例对象呢?所以我不能在每个节点上设置不同的AnimationClip属性值,
不能重新实例化,
cc.loader.loadRes方法也不会实例化AnimationClip的新对象,
(but why is AnimationClip singleton object?, so I can’t set different property values of AnimationClip on each nodes,
it’s can’t be newly instantiate,
also cc.loader.loadRes method don’t instantiate new object of AnimationClip,)
那我该怎么办?
如何创建许多AnimationClip对象(请不要创建AnimationClip.createWithSpriteFrames)并在运行时设置不同的属性值?
(so what can I do?
how I can create many AnimationClip object (please, not AnimationClip.createWithSpriteFrames)and set different property values at runtime?)
还是如何在运行时克隆AnimationClip对象,而不是手动创建?
我尝试手动克隆AnimationClip对象,但是播放此AnimationClip时却出现黑屏。
(or how to clone an AnimationClip object at runtime instead of manually create?
I tried to clone AnimationClip object manually, but blackscreen when play this AnimationClip.)
I’M sorry, chinese, english they are not my primary language.
thank you