protected virtual float[] ParsePropTypeScaleLock(CCNode node, CCNode parent, CCBReader reader, string propertyName) { float x = reader.ReadFloat(); float y = reader.ReadFloat(); var type = (CCBScaleType)reader.ReadInt(false); CCBHelper.SetRelativeScale(node, x, y, type, propertyName); if (reader.AnimatedProperties.Contains(propertyName)) { var baseValue = new List <CCBValue> { new CCBValue(x), new CCBValue(y), new CCBValue((int)type) }; reader.AnimationManager.SetBaseValue(baseValue, node, propertyName); } if (type == CCBScaleType.MultiplyResolution) { x *= CCBReader.ResolutionScale; y *= CCBReader.ResolutionScale; } var scaleLock = new float[2]; scaleLock[0] = x; scaleLock[1] = y; return(scaleLock); }
protected virtual CCPoint ParsePropTypePosition(CCNode node, CCNode parent, CCBReader reader, string propertyName) { float x = reader.ReadFloat(); float y = reader.ReadFloat(); var type = (CCBPositionType)reader.ReadInt(false); CCSize containerSize = reader.AnimationManager.GetContainerSize(parent); CCPoint pt = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, containerSize, propertyName); node.Position = CCBHelper.GetAbsolutePosition(pt, type, containerSize, propertyName); if (reader.AnimatedProperties.Contains(propertyName)) { var baseValue = new List <CCBValue> { new CCBValue(x), new CCBValue(y), new CCBValue((int)type) }; reader.AnimationManager.SetBaseValue(baseValue, node, propertyName); } return(pt); }
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 = CCBKeyframeEasing.Linear; // Animate CCActionInterval 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 { // [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 == "opacity") { byte opacity = ((CCBValue)pValue).GetByteValue(); ((ICCRGBAProtocol)node).Opacity = opacity; } else if (pPropName == "displayFrame") { ((CCSprite)node).DisplayFrame = (CCSpriteFrame)pValue; } else if (pPropName == "color") { var color = (CCColor3BWapper)pValue; ((CCSprite)node).Color = color.getColor(); } else { CCLog.Log("unsupported property name is {0}", pPropName); Debug.Assert(false, "unsupported property now"); } } } }
private CCActionInterval GetAction(CCBKeyframe pKeyframe0, CCBKeyframe pKeyframe1, string pPropName, CCNode node) { float duration = pKeyframe1.Time - (pKeyframe0 != null ? pKeyframe0.Time : 0); switch (pPropName) { 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.getColor(); 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)); } default: CCLog.Log("CCBReader: Failed to create animation for property: {0}", pPropName); break; } return(null); }