private void SetAnimatedProperty(string pPropName, CCNode node, object pValue, float fTweenDuraion) { if (fTweenDuraion > 0) { // Create a fake keyframe to generate the action from var kf1 = new CCBKeyframe(); kf1.Value = pValue; kf1.Time = fTweenDuraion; kf1.EasingType = CCBEasingType.Linear; // Animate CCFiniteTimeAction tweenAction = GetAction(null, kf1, pPropName, node); node.RunAction(tweenAction); } else { // Just set the value if (pPropName == "position") { // Get position type var array = (List <CCBValue>)GetBaseValue(node, pPropName); var type = (CCBPositionType)array[2].GetIntValue(); // Get relative position var value = (List <CCBValue>)pValue; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); node.Position = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, GetContainerSize(node.Parent), pPropName); } else if (pPropName == "scale") { // Get scale type var array = (List <CCBValue>)GetBaseValue(node, pPropName); var type = (CCBScaleType)array[2].GetIntValue(); // Get relative scale var value = (List <CCBValue>)pValue; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); CCBHelper.SetRelativeScale(node, x, y, type, pPropName); } else if (pPropName == "skew") { // Get relative scale var value = (List <CCBValue>)pValue; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); node.SkewX = x; node.SkewY = y; } else { // [node setValue:value forKey:name]; // TODO only handle rotation, opacity, displayFrame, color if (pPropName == "rotation") { float rotate = ((CCBValue)pValue).GetFloatValue(); node.Rotation = rotate; } else if (pPropName == "rotationX") { float rotate = ((CCBValue)pValue).GetFloatValue(); node.RotationX = rotate; } else if (pPropName == "rotationY") { float rotate = ((CCBValue)pValue).GetFloatValue(); node.RotationY = rotate; } else if (pPropName == "opacity") { byte opacity = ((CCBValue)pValue).GetByteValue(); node.Opacity = opacity; } else if (pPropName == "displayFrame") { ((CCSprite)node).SpriteFrame = (CCSpriteFrame)pValue; } else if (pPropName == "color") { var color = (CCColor3BWapper)pValue; node.Color = color.Color; } else if (pPropName == "visible") { bool visible = ((CCBValue)pValue).GetBoolValue(); node.Visible = visible; } else { CCLog.Log("unsupported property name is {0}", pPropName); Debug.Assert(false, "unsupported property now"); } } } }
private CCFiniteTimeAction GetAction(CCBKeyframe pKeyframe0, CCBKeyframe pKeyframe1, string pPropName, CCNode node) { float duration = pKeyframe1.Time - (pKeyframe0 != null ? pKeyframe0.Time : 0); switch (pPropName) { case "rotationX": { CCBValue value = (CCBValue)pKeyframe1.Value; return(new CCBRotateXTo(duration, value.GetFloatValue())); } case "rotationY": { CCBValue value = (CCBValue)pKeyframe1.Value; return(new CCBRotateYTo(duration, value.GetFloatValue())); } case "rotation": { var value = (CCBValue)pKeyframe1.Value; return(new CCBRotateTo(duration, value.GetFloatValue())); } case "opacity": { var value = (CCBValue)pKeyframe1.Value; return(new CCFadeTo(duration, value.GetByteValue())); } case "color": { var color = (CCColor3BWapper)pKeyframe1.Value; CCColor3B c = color.Color; return(new CCTintTo(duration, c.R, c.G, c.B)); } case "visible": { var value = (CCBValue)pKeyframe1.Value; if (value.GetBoolValue()) { return(new CCSequence(new CCDelayTime(duration), new CCShow())); } return(new CCSequence(new CCDelayTime(duration), new CCHide())); } case "displayFrame": return(new CCSequence(new CCDelayTime(duration), new CCBSetSpriteFrame((CCSpriteFrame)pKeyframe1.Value))); case "position": { // Get position type var array = (List <CCBValue>)GetBaseValue(node, pPropName); var type = (CCBPositionType)array[2].GetIntValue(); // Get relative position var value = (List <CCBValue>)pKeyframe1.Value; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); CCSize containerSize = GetContainerSize(node.Parent); CCPoint absPos = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, containerSize, pPropName); return(new CCMoveTo(duration, absPos)); } case "scale": { // Get position type var array = (List <CCBValue>)GetBaseValue(node, pPropName); var type = (CCBScaleType)array[2].GetIntValue(); // Get relative scale var value = (List <CCBValue>)pKeyframe1.Value; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); if (type == CCBScaleType.MultiplyResolution) { float resolutionScale = CCBReader.ResolutionScale; x *= resolutionScale; y *= resolutionScale; } return(new CCScaleTo(duration, x, y)); } case "skew": { // Get relative skew var value = (List <CCBValue>)pKeyframe1.Value; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); return(new CCSkewTo(duration, x, y)); } default: CCLog.Log("CCBReader: Failed to create animation for property: {0}", pPropName); break; } return(null); }