protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { if (propertyName == PROPERTY_NORMALDISPLAYFRAME) { if (spriteFrame != null) { ((CCMenuItemImage) node).SetNormalSpriteFrame(spriteFrame); } } else if (propertyName == PROPERTY_SELECTEDDISPLAYFRAME) { if (spriteFrame != null) { ((CCMenuItemImage) node).SetSelectedSpriteFrame(spriteFrame); } } else if (propertyName == PROPERTY_DISABLEDDISPLAYFRAME) { if (spriteFrame != null) { ((CCMenuItemImage) node).SetDisabledSpriteFrame(spriteFrame); } } else { base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader); } }
protected bool InitWithAnimation(CCAnimation pAnimation) { Debug.Assert(pAnimation != null); float singleDuration = pAnimation.Duration; if (base.InitWithDuration(singleDuration * pAnimation.Loops)) { m_nNextFrame = 0; m_pAnimation = pAnimation; m_pOrigFrame = null; m_uExecutedLoops = 0; m_pSplitTimes.Capacity = pAnimation.Frames.Count; float accumUnitsOfTime = 0; float newUnitOfTimeValue = singleDuration / pAnimation.TotalDelayUnits; var pFrames = pAnimation.Frames; //TODO: CCARRAY_VERIFY_TYPE(pFrames, CCAnimationFrame *); foreach (var pObj in pFrames) { var frame = (CCAnimationFrame) pObj; float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration; accumUnitsOfTime += frame.DelayUnits; m_pSplitTimes.Add(value); } return true; } return false; }
protected internal override void StartWithTarget(CCNode target) { base.StartWithTarget(target); var pSprite = (CCSprite) (target); m_pOrigFrame = null; if (m_pAnimation.RestoreOriginalFrame) { m_pOrigFrame = pSprite.DisplayFrame; } m_nNextFrame = 0; m_uExecutedLoops = 0; }
public SpriteAnimationSplit() { CCSize s = CCDirector.SharedDirector.WinSize; CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation"); // manually add frames to the frame cache CCSpriteFrame frame0 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 0, 132, 132)); CCSpriteFrame frame1 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 0, 132, 132)); CCSpriteFrame frame2 = new CCSpriteFrame(texture, new CCRect(132 * 2, 132 * 0, 132, 132)); CCSpriteFrame frame3 = new CCSpriteFrame(texture, new CCRect(132 * 3, 132 * 0, 132, 132)); CCSpriteFrame frame4 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 1, 132, 132)); CCSpriteFrame frame5 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 1, 132, 132)); // // Animation using Sprite BatchNode // CCSprite sprite = new CCSprite(frame0); sprite.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2)); AddChild(sprite); var animFrames = new List<CCSpriteFrame>(6); animFrames.Add(frame0); animFrames.Add(frame1); animFrames.Add(frame2); animFrames.Add(frame3); animFrames.Add(frame4); animFrames.Add(frame5); CCAnimation animation = new CCAnimation(animFrames, 0.2f); CCAnimate animate = new CCAnimate (animation); CCActionInterval seq = (CCActionInterval)(new CCSequence(animate, new CCFlipX(true), (CCFiniteTimeAction)animate.Copy(), new CCFlipX(false) )); sprite.RunAction(new CCRepeatForever (seq)); //animFrames->release(); // win32 : memory leak 2010-0415 }
protected virtual bool InitWithFile(string fileName) { Debug.Assert(!String.IsNullOrEmpty(fileName), "Invalid filename for sprite"); m_TextureFile = fileName; CCSpriteFrame pFrame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(fileName); if (pFrame != null) { return(InitWithSpriteFrame(pFrame)); } CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(fileName); if (null != pTexture) { var rect = new CCRect(); rect.Size = pTexture.ContentSize; return(InitWithTexture(pTexture, rect)); } return(false); }
protected virtual CCSpriteFrame ParsePropTypeSpriteFrame(CCNode node, CCNode parent, CCBReader reader, string propertyName) { string spriteSheet = reader.ReadCachedString(); string spriteFile = reader.ReadCachedString(); CCSpriteFrame spriteFrame = null; if (spriteFile.Length != 0) { if (spriteSheet.Length == 0) { CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile)); var bounds = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height); spriteFrame = new CCSpriteFrame(texture, bounds); } else { CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; // Load the sprite sheet only if it is not loaded if (!reader.LoadedSpriteSheet.Contains(spriteSheet)) { frameCache.AddSpriteFramesWithFile(spriteSheet); reader.LoadedSpriteSheet.Add(spriteSheet); } spriteFrame = frameCache.SpriteFrameByName(spriteFile); } if (reader.AnimatedProperties.Contains(propertyName)) { reader.AnimationManager.SetBaseValue(spriteFrame, node, propertyName); } } return(spriteFrame); }
public void SetSelectedSpriteFrame(CCSpriteFrame frame) { SelectedImage = new CCSprite(frame); }
/** * Sets the background spriteFrame to use for the specified button state. * * @param spriteFrame The background spriteFrame to use for the specified state. * @param state The state that uses the specified image. The values are described * in "CCControlState". */ public virtual void SetBackgroundSpriteFrameForState(CCSpriteFrame spriteFrame, CCControlState state) { CCScale9Sprite sprite = new CCScale9SpriteFrame(spriteFrame); SetBackgroundSpriteForState(sprite, state); }
public CCBSetSpriteFrame(CCSpriteFrame pSpriteFrame) { InitWithSpriteFrame(pSpriteFrame); }
public void AddSprite(CCSprite sprite) { CCSpriteFrame f = new CCSpriteFrame(sprite.Texture, new CCRect(0, 0, sprite.ContentSize.Width, sprite.ContentSize.Height)); AddSpriteFrame(f); }
public void AddSpriteFrame(CCSpriteFrame pFrame) { var animFrame = new CCAnimationFrame(); animFrame.InitWithSpriteFrame(pFrame, 1.0f, null); m_pFrames.Add(animFrame); // update duration m_fTotalDelayUnits++; }
public CCAnimate CreateAnimateAction() { var frameList = new List<CCSpriteFrame>(); for (var i = 0; i < 7; i++) { var texture = CreateCharacterTexture(); var sprite = new CCSpriteFrame(texture, new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height)); frameList.Add(sprite); } var animation = new CCAnimation(frameList, 0.1f); var animate = new CCAnimate (animation); return animate; }
protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { if (propertyName == PROPERTY_NORMALDISPLAYFRAME) { if (spriteFrame != null) { ((CCMenuItemImage)node).SetNormalSpriteFrame(spriteFrame); } } else if (propertyName == PROPERTY_SELECTEDDISPLAYFRAME) { if (spriteFrame != null) { ((CCMenuItemImage)node).SetSelectedSpriteFrame(spriteFrame); } } else if (propertyName == PROPERTY_DISABLEDDISPLAYFRAME) { if (spriteFrame != null) { ((CCMenuItemImage)node).SetDisabledSpriteFrame(spriteFrame); } } else { base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader); } }
public void SetSpriteFrame(CCSpriteFrame spriteFrame) { CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9); UpdateWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, CCRect.Zero); // Reset insets _insetLeft = 0; _insetTop = 0; _insetRight = 0; _insetBottom = 0; }
public virtual bool InitWithSpriteFrame(CCSpriteFrame spriteFrame) { Debug.Assert(spriteFrame != null, "Invalid spriteFrame for sprite"); bool pReturn = InitWithSpriteFrame(spriteFrame, CCRect.Zero); return pReturn; }
public virtual bool InitWithSpriteFrame(CCSpriteFrame spriteFrame, CCRect capInsets) { Debug.Assert(spriteFrame != null, "Sprite frame must be not nil"); CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9); bool pReturn = InitWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, capInsets); return pReturn; }
protected virtual void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { CCLog.Log("Unexpected property type: '{0}'!", propertyName); Debug.Assert(false); }
private void LoadCocos2DDictionary(PlistDictionary dict, CCTexture2D texture) { PlistDictionary metadataDict = null; if (dict.ContainsKey("metadata")) { metadataDict = dict["metadata"].AsDictionary; } PlistDictionary framesDict = null; if (dict.ContainsKey("frames")) { framesDict = dict["frames"].AsDictionary; } // get the format int format = 0; if (metadataDict != null) { format = metadataDict["format"].AsInt; } // check the format if (format < 0 || format > 3) { throw (new NotSupportedException("PList format " + format + " is not supported.")); } foreach (var pair in framesDict) { PlistDictionary frameDict = pair.Value.AsDictionary; CCSpriteFrame spriteFrame = null; if (format == 0) { float x = 0f, y = 0f, w = 0f, h = 0f; x = frameDict["x"].AsFloat; y = frameDict["y"].AsFloat; w = frameDict["width"].AsFloat; h = frameDict["height"].AsFloat; float ox = 0f, oy = 0f; ox = frameDict["offsetX"].AsFloat; oy = frameDict["offsetY"].AsFloat; int ow = 0, oh = 0; ow = frameDict["originalWidth"].AsInt; oh = frameDict["originalHeight"].AsInt; // check ow/oh if (ow == 0 || oh == 0) { CCLog.Log( "cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag"); } // abs ow/oh ow = Math.Abs(ow); oh = Math.Abs(oh); // create frame spriteFrame = new CCSpriteFrame( texture, new CCRect(x, y, w, h), false, new CCPoint(ox, oy), new CCSize(ow, oh) ); } else if (format == 1 || format == 2) { var frame = CCRect.Parse(frameDict["frame"].AsString); bool rotated = false; // rotation if (format == 2) { if (frameDict.ContainsKey("rotated")) { rotated = frameDict["rotated"].AsBool; } } var offset = CCPoint.Parse(frameDict["offset"].AsString); var sourceSize = CCSize.Parse(frameDict["sourceSize"].AsString); // create frame spriteFrame = new CCSpriteFrame(texture, frame, rotated, offset, sourceSize); } else if (format == 3) { var spriteSize = CCSize.Parse(frameDict["spriteSize"].AsString); var spriteOffset = CCPoint.Parse(frameDict["spriteOffset"].AsString); var spriteSourceSize = CCSize.Parse(frameDict["spriteSourceSize"].AsString); var textureRect = CCRect.Parse(frameDict["textureRect"].AsString); bool textureRotated = false; if (frameDict.ContainsKey("textureRotated")) { textureRotated = frameDict["textureRotated"].AsBool; } // get aliases var aliases = frameDict["aliases"].AsArray; for (int i = 0; i < aliases.Count; i++) { string oneAlias = aliases[i].AsString; if (_spriteFramesAliases.ContainsKey(oneAlias)) { if (_spriteFramesAliases[oneAlias] != null) { CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", oneAlias); } } if (!_spriteFramesAliases.ContainsKey(oneAlias)) { _spriteFramesAliases.Add(oneAlias, pair.Key); } } // create frame spriteFrame = new CCSpriteFrame( texture, new CCRect(textureRect.Origin.X, textureRect.Origin.Y, spriteSize.Width, spriteSize.Height), textureRotated, spriteOffset, spriteSourceSize ); } _spriteFrames[pair.Key] = spriteFrame; } AutoCreateAliasList(); }
public CCScale9SpriteFrame(CCSpriteFrame spriteFrame) { InitWithSpriteFrame(spriteFrame); }
public void AddSpriteFrameWithTexture(CCTexture2D pobTexture, CCRect rect) { CCSpriteFrame pFrame = new CCSpriteFrame(pobTexture, rect); AddSpriteFrame(pFrame); }
public CCScale9SpriteFrame(CCSpriteFrame spriteFrame, CCRect capInsets) { InitWithSpriteFrame(spriteFrame, capInsets); }
public void AddSpriteFrame(CCSpriteFrame pobFrame, string pszFrameName) { if (!_AllowFrameOverwrite && m_pSpriteFrames.ContainsKey(pszFrameName)) { throw (new ArgumentException("The frame named " + pszFrameName + " already exists.")); } m_pSpriteFrames[pszFrameName] = pobFrame; }
public virtual void ParseProperties(CCNode node, CCNode parent, CCBReader reader) { int numRegularProps = reader.ReadInt(false); int numExturaProps = reader.ReadInt(false); int propertyCount = numRegularProps + numExturaProps; for (int i = 0; i < propertyCount; i++) { bool isExtraProp = (i >= numRegularProps); int type = reader.ReadInt(false); string propertyName = reader.ReadCachedString(); // Check if the property can be set for this platform bool setProp = false; var platform = (CCBPlatform)reader.ReadByte(); if (platform == CCBPlatform.All) { setProp = true; } #if __CC_PLATFORM_IOS if (platform == kCCBPlatform.kCCBPlatformIOS) { setProp = true; } #elif __CC_PLATFORM_MAC if (platform == kCCBPlatform.kCCBPlatformMac) { setProp = true; } #endif // Forward properties for sub ccb files if (node is CCBFile) { var ccbNode = (CCBFile)node; if (ccbNode.FileNode != null && isExtraProp) { node = ccbNode.FileNode; // Skip properties that doesn't have a value to override var extraPropsNames = (List <string>)node.UserObject; setProp &= extraPropsNames.Contains(propertyName); } } else if (isExtraProp && node == reader.AnimationManager.RootNode) { var extraPropsNames = (List <string>)node.UserObject; if (extraPropsNames == null) { extraPropsNames = new List <string>(); node.UserObject = extraPropsNames; } extraPropsNames.Add(propertyName); } switch ((CCBPropType)type) { case CCBPropType.Position: { CCPoint position = ParsePropTypePosition(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypePosition(node, parent, propertyName, position, reader); } break; } case CCBPropType.Point: { CCPoint point = ParsePropTypePoint(node, parent, reader); if (setProp) { OnHandlePropTypePoint(node, parent, propertyName, point, reader); } break; } case CCBPropType.PointLock: { CCPoint pointLock = ParsePropTypePointLock(node, parent, reader); if (setProp) { OnHandlePropTypePointLock(node, parent, propertyName, pointLock, reader); } break; } case CCBPropType.Size: { CCSize size = ParsePropTypeSize(node, parent, reader); if (setProp) { OnHandlePropTypeSize(node, parent, propertyName, size, reader); } break; } case CCBPropType.ScaleLock: { float[] scaleLock = ParsePropTypeScaleLock(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeScaleLock(node, parent, propertyName, scaleLock, reader); } break; } case CCBPropType.Float: { float f = ParsePropTypeFloat(node, parent, reader); if (setProp) { OnHandlePropTypeFloat(node, parent, propertyName, f, reader); } break; } case CCBPropType.Degrees: { float degrees = ParsePropTypeDegrees(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeDegrees(node, parent, propertyName, degrees, reader); } break; } case CCBPropType.FloatScale: { float floatScale = ParsePropTypeFloatScale(node, parent, reader); if (setProp) { OnHandlePropTypeFloatScale(node, parent, propertyName, floatScale, reader); } break; } case CCBPropType.Integer: { int integer = ParsePropTypeInteger(node, parent, reader); if (setProp) { OnHandlePropTypeInteger(node, parent, propertyName, integer, reader); } break; } case CCBPropType.IntegerLabeled: { int integerLabeled = ParsePropTypeIntegerLabeled(node, parent, reader); if (setProp) { OnHandlePropTypeIntegerLabeled(node, parent, propertyName, integerLabeled, reader); } break; } case CCBPropType.FloatVar: { float[] floatVar = ParsePropTypeFloatVar(node, parent, reader); if (setProp) { OnHandlePropTypeFloatVar(node, parent, propertyName, floatVar, reader); } break; } case CCBPropType.Check: { bool check = ParsePropTypeCheck(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeCheck(node, parent, propertyName, check, reader); } break; } case CCBPropType.SpriteFrame: { CCSpriteFrame ccSpriteFrame = ParsePropTypeSpriteFrame(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeSpriteFrame(node, parent, propertyName, ccSpriteFrame, reader); } break; } case CCBPropType.Animation: { CCAnimation ccAnimation = ParsePropTypeAnimation(node, parent, reader); if (setProp) { OnHandlePropTypeAnimation(node, parent, propertyName, ccAnimation, reader); } break; } case CCBPropType.Texture: { CCTexture2D ccTexture2D = ParsePropTypeTexture(node, parent, reader); if (setProp) { OnHandlePropTypeTexture(node, parent, propertyName, ccTexture2D, reader); } break; } case CCBPropType.Byte: { byte b = ParsePropTypeByte(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeByte(node, parent, propertyName, b, reader); } break; } case CCBPropType.Color3: { CCColor3B color3B = ParsePropTypeColor3(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeColor3(node, parent, propertyName, color3B, reader); } break; } case CCBPropType.Color4FVar: { CCColor4F[] color4FVar = ParsePropTypeColor4FVar(node, parent, reader); if (setProp) { OnHandlePropTypeColor4FVar(node, parent, propertyName, color4FVar, reader); } break; } case CCBPropType.Flip: { bool[] flip = ParsePropTypeFlip(node, parent, reader); if (setProp) { OnHandlePropTypeFlip(node, parent, propertyName, flip, reader); } break; } case CCBPropType.Blendmode: { CCBlendFunc blendFunc = ParsePropTypeBlendFunc(node, parent, reader); if (setProp) { OnHandlePropTypeBlendFunc(node, parent, propertyName, blendFunc, reader); } break; } case CCBPropType.FntFile: { string fntFile = ParsePropTypeFntFile(node, parent, reader); if (setProp) { OnHandlePropTypeFntFile(node, parent, propertyName, fntFile, reader); } break; } case CCBPropType.FontTTF: { string fontTTF = ParsePropTypeFontTTF(node, parent, reader); if (setProp) { OnHandlePropTypeFontTTF(node, parent, propertyName, fontTTF, reader); } break; } case CCBPropType.String: { string s = ParsePropTypeString(node, parent, reader); if (setProp) { OnHandlePropTypeString(node, parent, propertyName, s, reader); } break; } case CCBPropType.Text: { string text = ParsePropTypeText(node, parent, reader); if (setProp) { OnHandlePropTypeText(node, parent, propertyName, text, reader); } break; } case CCBPropType.Block: { BlockData blockData = ParsePropTypeBlock(node, parent, reader); if (setProp) { OnHandlePropTypeBlock(node, parent, propertyName, blockData, reader); } break; } case CCBPropType.BlockCCControl: { BlockCCControlData blockCCControlData = ParsePropTypeBlockCcControl(node, parent, reader); if (setProp && blockCCControlData != null) { OnHandlePropTypeBlockCcControl(node, parent, propertyName, blockCCControlData, reader); } break; } case CCBPropType.CCBFile: { CCNode ccbFileNode = ParsePropTypeCcbFile(node, parent, reader); if (setProp) { OnHandlePropTypeCCBFile(node, parent, propertyName, ccbFileNode, reader); } break; } default: //ASSERT_FAIL_UNEXPECTED_PROPERTYTYPE(type); break; } } }
public CCMaskedSprite(CCSpriteFrame pSpriteFrame, byte[] mask) : base(pSpriteFrame) { _MyMask = mask; }
protected virtual bool InitWithSpriteFrame(CCSpriteFrame pSpriteFrame) { mSpriteFrame = pSpriteFrame; return true; }
private void LoadAppleDictionary(PlistDictionary dict, CCTexture2D texture) { var version = dict.ContainsKey ("version") ? dict ["version"].AsInt : 0; if (version != 1) throw (new NotSupportedException("Binary PList version " + version + " is not supported.")); var images = dict.ContainsKey ("images") ? dict ["images"].AsArray : null; foreach (var imageEntry in images) { // we only support one image for now var imageDict = imageEntry.AsDictionary; var path = imageDict ["path"].AsString; path = Path.Combine(plistFilePath, CCFileUtils.RemoveExtension(path)); if (!CCTextureCache.SharedTextureCache.Contains (path)) texture = CCTextureCache.SharedTextureCache.AddImage (path); else texture = CCTextureCache.SharedTextureCache[path]; // size not used right now //var size = CCSize.Parse(imageDict ["size"].AsString); var subImages = imageDict ["subimages"].AsArray; foreach (var subImage in subImages) { CCSpriteFrame spriteFrame = null; var subImageDict = subImage.AsDictionary; var name = subImageDict ["name"].AsString; var alias = subImageDict ["alias"].AsString; var isFullyOpaque = true; if (subImageDict.ContainsKey ("isFullyOpaque")) isFullyOpaque = subImageDict ["isFullyOpaque"].AsBool; var textureRect = CCRect.Parse (subImageDict ["textureRect"].AsString); var spriteOffset = CCPoint.Parse (subImageDict ["spriteOffset"].AsString); // We are going to override the sprite offset for now to be 0,0 // It seems the offset is calculated off of the original size but if // we pass this offset it throws our center position calculations off. spriteOffset = CCPoint.Zero; var textureRotated = false; if (subImageDict.ContainsKey ("textureRotated")) { textureRotated = subImageDict ["textureRotated"].AsBool; } var spriteSourceSize = CCSize.Parse (subImageDict ["spriteSourceSize"].AsString); var frameRect = textureRect; if (textureRotated) frameRect = new CCRect (textureRect.Origin.X, textureRect.Origin.Y, textureRect.Size.Height, textureRect.Size.Width); #if DEBUG CCLog.Log ("texture {0} rect {1} rotated {2} offset {3}, sourcesize {4}", name, textureRect, textureRotated, spriteOffset, spriteSourceSize); #endif // create frame spriteFrame = new CCSpriteFrame ( texture, frameRect, textureRotated, spriteOffset, spriteSourceSize ); _spriteFrames [name] = spriteFrame; } } }
public void SetNormalSpriteFrame(CCSpriteFrame frame) { NormalImage = new CCSprite(frame); }
private void LoadCocos2DDictionary(PlistDictionary dict, CCTexture2D texture) { PlistDictionary metadataDict = null; if (dict.ContainsKey("metadata")) { metadataDict = dict["metadata"].AsDictionary; } PlistDictionary framesDict = null; if (dict.ContainsKey("frames")) { framesDict = dict["frames"].AsDictionary; } // get the format int format = 0; if (metadataDict != null) { format = metadataDict["format"].AsInt; } // check the format if (format < 0 || format > 3) { throw (new NotSupportedException("PList format " + format + " is not supported.")); } foreach (var pair in framesDict) { PlistDictionary frameDict = pair.Value.AsDictionary; CCSpriteFrame spriteFrame = null; if (format == 0) { float x = 0f, y = 0f, w = 0f, h = 0f; x = frameDict["x"].AsFloat; y = frameDict["y"].AsFloat; w = frameDict["width"].AsFloat; h = frameDict["height"].AsFloat; float ox = 0f, oy = 0f; ox = frameDict["offsetX"].AsFloat; oy = frameDict["offsetY"].AsFloat; int ow = 0, oh = 0; ow = frameDict["originalWidth"].AsInt; oh = frameDict["originalHeight"].AsInt; // check ow/oh if (ow == 0 || oh == 0) { CCLog.Log( "cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag"); } // abs ow/oh ow = Math.Abs(ow); oh = Math.Abs(oh); // create frame spriteFrame = new CCSpriteFrame( texture, new CCRect(x, y, w, h), false, new CCPoint(ox, oy), new CCSize(ow, oh) ); } else if (format == 1 || format == 2) { var frame = CCRect.Parse(frameDict["frame"].AsString); bool rotated = false; // rotation if (format == 2) { if (frameDict.ContainsKey("rotated")) { rotated = frameDict["rotated"].AsBool; } } var offset = CCPoint.Parse(frameDict["offset"].AsString); var sourceSize = CCSize.Parse(frameDict["sourceSize"].AsString); // create frame spriteFrame = new CCSpriteFrame(texture, frame, rotated, offset, sourceSize); } else if (format == 3) { var spriteSize = CCSize.Parse(frameDict["spriteSize"].AsString); var spriteOffset = CCPoint.Parse(frameDict["spriteOffset"].AsString); var spriteSourceSize = CCSize.Parse(frameDict["spriteSourceSize"].AsString); var textureRect = CCRect.Parse(frameDict["textureRect"].AsString); bool textureRotated = false; if (frameDict.ContainsKey("textureRotated")) { textureRotated = frameDict["textureRotated"].AsBool; } // get aliases var aliases = frameDict["aliases"].AsArray; for (int i = 0; i < aliases.Count; i++ ) { string oneAlias = aliases[i].AsString; if (_spriteFramesAliases.ContainsKey(oneAlias)) { if (_spriteFramesAliases[oneAlias] != null) { CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", oneAlias); } } if (!_spriteFramesAliases.ContainsKey(oneAlias)) { _spriteFramesAliases.Add(oneAlias, pair.Key); } } // create frame spriteFrame = new CCSpriteFrame( texture, new CCRect(textureRect.Origin.X, textureRect.Origin.Y, spriteSize.Width, spriteSize.Height), textureRotated, spriteOffset, spriteSourceSize ); } _spriteFrames[pair.Key] = spriteFrame; } }
public void SetDisabledSpriteFrame(CCSpriteFrame frame) { DisabledImage = new CCSprite(frame); }
protected virtual bool InitWithSpriteFrame(CCSpriteFrame pSpriteFrame) { mSpriteFrame = pSpriteFrame; return(true); }
private CCBKeyframe ReadKeyframe(CCBPropType type) { var keyframe = new CCBKeyframe(); keyframe.Time = ReadFloat(); var easingType = (CCBKeyframeEasing)ReadInt(false); float easingOpt = 0; object value = null; if (easingType == CCBKeyframeEasing.CubicIn || easingType == CCBKeyframeEasing.CubicOut || easingType == CCBKeyframeEasing.CubicInOut || easingType == CCBKeyframeEasing.ElasticIn || easingType == CCBKeyframeEasing.ElasticOut || easingType == CCBKeyframeEasing.ElasticInOut) { easingOpt = ReadFloat(); } keyframe.EasingType = easingType; keyframe.EasingOpt = easingOpt; if (type == CCBPropType.Check) { value = new CCBValue(ReadBool()); } else if (type == CCBPropType.Byte) { value = new CCBValue(ReadByte()); } else if (type == CCBPropType.Color3) { byte r = ReadByte(); byte g = ReadByte(); byte b = ReadByte(); var c = new CCColor3B(r, g, b); value = new CCColor3BWapper(c); } else if (type == CCBPropType.Degrees) { value = new CCBValue(ReadFloat()); } else if (type == CCBPropType.ScaleLock || type == CCBPropType.Position) { float a = ReadFloat(); float b = ReadFloat(); value = new List <CCBValue> { new CCBValue(a), new CCBValue(b) }; } else if (type == CCBPropType.SpriteFrame) { string spriteSheet = ReadCachedString(); string spriteFile = ReadCachedString(); CCSpriteFrame spriteFrame; if (String.IsNullOrEmpty(spriteSheet)) { CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile)); var bounds = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height); spriteFrame = new CCSpriteFrame(texture, bounds); } else { CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; // Load the sprite sheet only if it is not loaded if (!mLoadedSpriteSheets.Contains(spriteSheet)) { frameCache.AddSpriteFramesWithFile(spriteSheet); mLoadedSpriteSheets.Add(spriteSheet); } spriteFrame = frameCache.SpriteFrameByName(spriteFile); } value = spriteFrame; } keyframe.Value = value; return(keyframe); }
protected virtual CCSpriteFrame ParsePropTypeSpriteFrame(CCNode node, CCNode parent, CCBReader reader, string propertyName) { string spriteSheet = reader.ReadCachedString(); string spriteFile = reader.ReadCachedString(); CCSpriteFrame spriteFrame = null; if (spriteFile.Length != 0) { if (spriteSheet.Length == 0) { spriteFile = reader.CCBRootPath + spriteFile; CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile)); var bounds = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height); spriteFrame = new CCSpriteFrame(texture, bounds); } else { CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; spriteSheet = reader.CCBRootPath + spriteSheet; // Load the sprite sheet only if it is not loaded if (!reader.LoadedSpriteSheet.Contains(spriteSheet)) { frameCache.AddSpriteFramesWithFile(spriteSheet); reader.LoadedSpriteSheet.Add(spriteSheet); } spriteFrame = frameCache.SpriteFrameByName(spriteFile); } if (reader.AnimatedProperties.Contains(propertyName)) { reader.AnimationManager.SetBaseValue(spriteFrame, node, propertyName); } } return spriteFrame; }
private void LoadAppleDictionary(PlistDictionary dict, CCTexture2D texture) { var version = dict.ContainsKey("version") ? dict ["version"].AsInt : 0; if (version != 1) { throw (new NotSupportedException("Binary PList version " + version + " is not supported.")); } var images = dict.ContainsKey("images") ? dict ["images"].AsArray : null; foreach (var imageEntry in images) { // we only support one image for now var imageDict = imageEntry.AsDictionary; var path = imageDict ["path"].AsString; path = Path.Combine(plistFilePath, CCFileUtils.RemoveExtension(path)); if (!CCTextureCache.SharedTextureCache.Contains(path)) { texture = CCTextureCache.SharedTextureCache.AddImage(path); } else { texture = CCTextureCache.SharedTextureCache[path]; } // size not used right now //var size = CCSize.Parse(imageDict ["size"].AsString); var subImages = imageDict ["subimages"].AsArray; foreach (var subImage in subImages) { CCSpriteFrame spriteFrame = null; var subImageDict = subImage.AsDictionary; var name = subImageDict ["name"].AsString; var alias = subImageDict ["alias"].AsString; var isFullyOpaque = true; if (subImageDict.ContainsKey("isFullyOpaque")) { isFullyOpaque = subImageDict ["isFullyOpaque"].AsBool; } var textureRect = CCRect.Parse(subImageDict ["textureRect"].AsString); var spriteOffset = CCPoint.Parse(subImageDict ["spriteOffset"].AsString); // We are going to override the sprite offset for now to be 0,0 // It seems the offset is calculated off of the original size but if // we pass this offset it throws our center position calculations off. spriteOffset = CCPoint.Zero; var textureRotated = false; if (subImageDict.ContainsKey("textureRotated")) { textureRotated = subImageDict ["textureRotated"].AsBool; } var spriteSourceSize = CCSize.Parse(subImageDict ["spriteSourceSize"].AsString); var frameRect = textureRect; if (textureRotated) { frameRect = new CCRect(textureRect.Origin.X, textureRect.Origin.Y, textureRect.Size.Height, textureRect.Size.Width); } #if DEBUG CCLog.Log("texture {0} rect {1} rotated {2} offset {3}, sourcesize {4}", name, textureRect, textureRotated, spriteOffset, spriteSourceSize); #endif // create frame spriteFrame = new CCSpriteFrame( texture, frameRect, textureRotated, spriteOffset, spriteSourceSize ); _spriteFrames [name] = spriteFrame; } } AutoCreateAliasList(); }
public void SetDisplayFrame(CCSpriteFrame spriteFrame) { Debug.Assert(spriteFrame.OffsetInPixels.Equals(CCPoint.Zero), "QuadParticle only supports SpriteFrames with no offsets"); // update texture before updating texture rect if (m_pTexture != null || spriteFrame.Texture.Name != m_pTexture.Name) { Texture = spriteFrame.Texture; } }
public bool IsFrameDisplayed(CCSpriteFrame pFrame) { CCRect r = pFrame.Rect; return ( CCRect.Equal(ref r, ref m_obRect) && pFrame.Texture.Name == m_pobTexture.Name && pFrame.Offset.Equals(m_obUnflippedOffsetPositionFromCenter) ); }
public void AddSpriteFrameWithFileName(string pszFileName) { CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(pszFileName); CCRect rect = CCRect.Zero; rect.Size = pTexture.ContentSize; CCSpriteFrame pFrame = new CCSpriteFrame(pTexture, rect); AddSpriteFrame(pFrame); }
public CCSprite (CCSpriteFrame pSpriteFrame) { if (!InitWithSpriteFrame(pSpriteFrame)) { CCLog.Log("CCSprite (CCSpriteFrame pSpriteFrame): Problems initializing class"); } }
private CCBKeyframe ReadKeyframe(CCBPropertyType type) { var keyframe = new CCBKeyframe(); keyframe.Time = ReadFloat(); var easingType = (CCBEasingType) ReadInt(false); float easingOpt = 0; object value = null; if (easingType == CCBEasingType.CubicIn || easingType == CCBEasingType.CubicOut || easingType == CCBEasingType.CubicInOut || easingType == CCBEasingType.ElasticIn || easingType == CCBEasingType.ElasticOut || easingType == CCBEasingType.ElasticInOut) { easingOpt = ReadFloat(); } keyframe.EasingType = easingType; keyframe.EasingOpt = easingOpt; if (type == CCBPropertyType.Check) { value = new CCBValue(ReadBool()); } else if (type == CCBPropertyType.Byte) { value = new CCBValue(ReadByte()); } else if (type == CCBPropertyType.Color3) { byte r = ReadByte(); byte g = ReadByte(); byte b = ReadByte(); var c = new CCColor3B(r, g, b); value = new CCColor3BWapper(c); } else if (type == CCBPropertyType.Degrees) { value = new CCBValue(ReadFloat()); } else if (type == CCBPropertyType.ScaleLock || type == CCBPropertyType.Position || type == CCBPropertyType.FloatXY) { float a = ReadFloat(); float b = ReadFloat(); value = new List<CCBValue> { new CCBValue(a), new CCBValue(b) }; } else if (type == CCBPropertyType.SpriteFrame) { string spriteSheet = ReadCachedString(); string spriteFile = ReadCachedString(); CCSpriteFrame spriteFrame; if (String.IsNullOrEmpty(spriteSheet)) { spriteFile = _CCBRootPath + spriteFile; CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile)); var bounds = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height); spriteFrame = new CCSpriteFrame(texture, bounds); } else { spriteSheet = _CCBRootPath + spriteSheet; CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; // Load the sprite sheet only if it is not loaded if (!_loadedSpriteSheets.Contains(spriteSheet)) { frameCache.AddSpriteFramesWithFile(spriteSheet); _loadedSpriteSheets.Add(spriteSheet); } spriteFrame = frameCache.SpriteFrameByName(spriteFile); } value = spriteFrame; } keyframe.Value = value; return keyframe; }
protected virtual bool InitWithSpriteFrame(CCSpriteFrame pSpriteFrame) { Debug.Assert(pSpriteFrame != null); bool bRet = InitWithTexture (pSpriteFrame.Texture, pSpriteFrame.Rect, pSpriteFrame.IsRotated); DisplayFrame = pSpriteFrame; return bRet; }
public void AddSpriteFramesWithDictionary(PlistDictionary pobDictionary, CCTexture2D pobTexture, string framePrefix) { /* * Supported Zwoptex Formats: * * ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version * ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b * ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1 * ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+ */ PlistDictionary metadataDict = null; if (pobDictionary.ContainsKey("metadata")) { metadataDict = pobDictionary["metadata"].AsDictionary; } PlistDictionary framesDict = null; if (pobDictionary.ContainsKey("frames")) { framesDict = pobDictionary["frames"].AsDictionary; } int format = 0; // get the format if (metadataDict != null) { format = metadataDict["format"].AsInt; } // check the format if (format < 0 || format > 3) { throw (new NotSupportedException("PList format " + format + " is not supported.")); } foreach (var pair in framesDict) { PlistDictionary frameDict = pair.Value.AsDictionary; CCSpriteFrame spriteFrame = null; if (format == 0) { float x = 0f, y = 0f, w = 0f, h = 0f; x = frameDict["x"].AsFloat; y = frameDict["y"].AsFloat; w = frameDict["width"].AsFloat; h = frameDict["height"].AsFloat; float ox = 0f, oy = 0f; ox = frameDict["offsetX"].AsFloat; oy = frameDict["offsetY"].AsFloat; int ow = 0, oh = 0; ow = frameDict["originalWidth"].AsInt; oh = frameDict["originalHeight"].AsInt; // check ow/oh if (ow == 0 || oh == 0) { CCLog.Log( "cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag"); } // abs ow/oh ow = Math.Abs(ow); oh = Math.Abs(oh); // create frame spriteFrame = new CCSpriteFrame(pobTexture, new CCRect(x, y, w, h), false, new CCPoint(ox, oy), new CCSize(ow, oh) ); } else if (format == 1 || format == 2) { CCRect frame = CCRect.Parse(frameDict["frame"].AsString); bool rotated = false; // rotation if (format == 2) { if (frameDict.ContainsKey("rotated")) { rotated = frameDict["rotated"].AsBool; } } CCPoint offset = CCPoint.Parse(frameDict["offset"].AsString); CCSize sourceSize = CCSize.Parse(frameDict["sourceSize"].AsString); // create frame spriteFrame = new CCSpriteFrame(pobTexture, frame, rotated, offset, sourceSize ); } else if (format == 3) { // get values CCSize spriteSize = CCSize.Parse(frameDict["spriteSize"].AsString); CCPoint spriteOffset = CCPoint.Parse(frameDict["spriteOffset"].AsString); CCSize spriteSourceSize = CCSize.Parse(frameDict["spriteSourceSize"].AsString); CCRect textureRect = CCRect.Parse(frameDict["textureRect"].AsString); bool textureRotated = false; if (frameDict.ContainsKey("textureRotated")) { textureRotated = frameDict["textureRotated"].AsBool; } // get aliases PlistArray aliases = frameDict["aliases"].AsArray; string frameKey = pair.Key; foreach (PlistObjectBase item2 in aliases) { string oneAlias = item2.AsString; if (m_pSpriteFramesAliases.Keys.Contains(oneAlias)) { if (m_pSpriteFramesAliases[oneAlias] != null) { CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", oneAlias); } } if (!m_pSpriteFramesAliases.Keys.Contains(oneAlias)) { m_pSpriteFramesAliases.Add(oneAlias, frameKey); } } // create frame spriteFrame = new CCSpriteFrame(pobTexture, new CCRect(textureRect.Origin.X, textureRect.Origin.Y, spriteSize.Width, spriteSize.Height), textureRotated, spriteOffset, spriteSourceSize); } // add sprite frame string key = framePrefix + pair.Key; if (!_AllowFrameOverwrite && m_pSpriteFrames.ContainsKey(key)) { CCLog.Log("Frame named " + key + " already exists in the animation cache. Not overwriting existing record."); } else if (_AllowFrameOverwrite || !m_pSpriteFrames.ContainsKey(key)) { m_pSpriteFrames[key] = spriteFrame; } } }
public void AddSpriteFramesWithDictionary(PlistDictionary pobDictionary, CCTexture2D pobTexture, string framePrefix) { /* Supported Zwoptex Formats: ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1 ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+ */ PlistDictionary metadataDict = null; if (pobDictionary.ContainsKey("metadata")) { metadataDict = pobDictionary["metadata"].AsDictionary; } PlistDictionary framesDict = null; if (pobDictionary.ContainsKey("frames")) { framesDict = pobDictionary["frames"].AsDictionary; } int format = 0; // get the format if (metadataDict != null) { format = metadataDict["format"].AsInt; } // check the format if (format < 0 || format > 3) { throw (new NotSupportedException("PList format " + format + " is not supported.")); } foreach (var pair in framesDict) { PlistDictionary frameDict = pair.Value.AsDictionary; CCSpriteFrame spriteFrame = null; if (format == 0) { float x=0f, y=0f, w=0f, h=0f; x = frameDict["x"].AsFloat; y = frameDict["y"].AsFloat; w = frameDict["width"].AsFloat; h = frameDict["height"].AsFloat; float ox = 0f, oy = 0f; ox = frameDict["offsetX"].AsFloat; oy = frameDict["offsetY"].AsFloat; int ow = 0, oh = 0; ow = frameDict["originalWidth"].AsInt; oh = frameDict["originalHeight"].AsInt; // check ow/oh if (ow == 0 || oh == 0) { CCLog.Log( "cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag"); } // abs ow/oh ow = Math.Abs(ow); oh = Math.Abs(oh); // create frame spriteFrame = new CCSpriteFrame(pobTexture, new CCRect(x, y, w, h), false, new CCPoint(ox, oy), new CCSize(ow, oh) ); } else if (format == 1 || format == 2) { CCRect frame = CCRect.Parse(frameDict["frame"].AsString); bool rotated = false; // rotation if (format == 2) { if (frameDict.ContainsKey("rotated")) { rotated = frameDict["rotated"].AsBool; } } CCPoint offset = CCPoint.Parse(frameDict["offset"].AsString); CCSize sourceSize = CCSize.Parse (frameDict["sourceSize"].AsString); // create frame spriteFrame = new CCSpriteFrame(pobTexture, frame, rotated, offset, sourceSize ); } else if (format == 3) { // get values CCSize spriteSize = CCSize.Parse (frameDict["spriteSize"].AsString); CCPoint spriteOffset = CCPoint.Parse(frameDict["spriteOffset"].AsString); CCSize spriteSourceSize = CCSize.Parse (frameDict["spriteSourceSize"].AsString); CCRect textureRect = CCRect.Parse(frameDict["textureRect"].AsString); bool textureRotated = false; if (frameDict.ContainsKey("textureRotated")) { textureRotated = frameDict["textureRotated"].AsBool; } // get aliases PlistArray aliases = frameDict["aliases"].AsArray; string frameKey = pair.Key; foreach (PlistObjectBase item2 in aliases) { string oneAlias = item2.AsString; if (m_pSpriteFramesAliases.Keys.Contains(oneAlias)) { if (m_pSpriteFramesAliases[oneAlias] != null) { CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", oneAlias); } } if (!m_pSpriteFramesAliases.Keys.Contains(oneAlias)) { m_pSpriteFramesAliases.Add(oneAlias, frameKey); } } // create frame spriteFrame = new CCSpriteFrame(pobTexture, new CCRect(textureRect.Origin.X, textureRect.Origin.Y, spriteSize.Width, spriteSize.Height), textureRotated, spriteOffset, spriteSourceSize); } // add sprite frame string key = framePrefix + pair.Key; if (!_AllowFrameOverwrite && m_pSpriteFrames.ContainsKey(key)) { CCLog.Log("Frame named " + key + " already exists in the animation cache. Not overwriting existing record."); } else if (_AllowFrameOverwrite || !m_pSpriteFrames.ContainsKey(key)) { m_pSpriteFrames[key] = spriteFrame; } } }
private void LoadAppleDictionary(PlistDictionary dict, CCTexture2D texture) { var version = dict.ContainsKey("version") ? dict ["version"].AsInt : 0; if (version != 1) { throw (new NotSupportedException("Binary PList version " + version + " is not supported.")); } var images = dict.ContainsKey("images") ? dict ["images"].AsArray : null; // we only support one image for now var imageDict = images [0].AsDictionary; var path = imageDict ["path"].AsString; // size not used right now //var size = CCSize.Parse(imageDict ["size"].AsString); var subImages = imageDict ["subimages"].AsArray; foreach (var subImage in subImages) { CCSpriteFrame spriteFrame = null; var subImageDict = subImage.AsDictionary; var name = subImageDict ["name"].AsString; var alias = subImageDict ["alias"].AsString; var isFullyOpaque = true; if (subImageDict.ContainsKey("isFullyOpaque")) { isFullyOpaque = subImageDict ["isFullyOpaque"].AsBool; } var textureRect = CCRect.Parse(subImageDict ["textureRect"].AsString); var spriteOffset = CCPoint.Parse(subImageDict ["spriteOffset"].AsString); var textureRotated = false; if (subImageDict.ContainsKey("textureRotated")) { textureRotated = subImageDict ["textureRotated"].AsBool; } var spriteSourceSize = CCSize.Parse(subImageDict ["spriteSourceSize"].AsString); var frameRect = textureRect; if (textureRotated) { frameRect = new CCRect(textureRect.Origin.X, textureRect.Origin.Y, textureRect.Size.Height, textureRect.Size.Width); } #if DEBUG CCLog.Log("texture {0} rect {1} rotated {2} offset {3}, sourcesize {4}", name, textureRect, textureRotated, spriteOffset, spriteSourceSize); #endif // create frame spriteFrame = new CCSpriteFrame( texture, frameRect, textureRotated, spriteOffset, spriteSourceSize ); _spriteFrames[name] = spriteFrame; } }