internal static CCTexture2D CreateNativeLabel(string text, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, string fontName, float fontSize, CCColor4B textColor) { if (string.IsNullOrEmpty(text)) { return new CCTexture2D(); } var font = CreateFont (fontName, fontSize); if (dimensions.Equals(CCSize.Zero)) { CreateBitmap(1, 1); var ms = _graphics.MeasureString(text, font); dimensions.Width = ms.Width; dimensions.Height = ms.Height; } CreateBitmap((int)dimensions.Width, (int)dimensions.Height); var stringFormat = new StringFormat(); switch (hAlignment) { case CCTextAlignment.Left: stringFormat.Alignment = StringAlignment.Near; break; case CCTextAlignment.Center: stringFormat.Alignment = StringAlignment.Center; break; case CCTextAlignment.Right: stringFormat.Alignment = StringAlignment.Far; break; } switch (vAlignment) { case CCVerticalTextAlignment.Top: stringFormat.LineAlignment = StringAlignment.Near; break; case CCVerticalTextAlignment.Center: stringFormat.LineAlignment = StringAlignment.Center; break; case CCVerticalTextAlignment.Bottom: stringFormat.LineAlignment = StringAlignment.Far; break; } _graphics.DrawString(text, font, _brush, new RectangleF(0, 0, dimensions.Width, dimensions.Height), stringFormat); _graphics.Flush(); var texture = new CCTexture2D(); texture.InitWithStream (SaveToStream(), Microsoft.Xna.Framework.Graphics.SurfaceFormat.Bgra4444); return texture; }
protected virtual bool InitWithSize(CCGridSize gridSize, CCTexture2D pTexture, bool bFlipped) { bool bRet = true; m_bActive = false; m_nReuseGrid = 0; m_sGridSize = gridSize; m_pTexture = pTexture; m_bIsTextureFlipped = bFlipped; CCSize texSize = m_pTexture.ContentSize; m_obStep.X = texSize.Width / m_sGridSize.X; m_obStep.Y = texSize.Height / m_sGridSize.Y; m_pGrabber = new CCGrabber(); if (m_pGrabber != null) { m_pGrabber.Grab(m_pTexture); } else { bRet = false; } //m_pShaderProgram = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture); CalculateVertexPoints(); return bRet; }
public bool initWithTexture(CCTexture2D aTexture) { if (base.InitWithTexture(aTexture)) { m_state = PaddleState.kPaddleStateUngrabbed; } return true; }
public static CCTextureAtlas CreateAtlasFromTexture2D(Microsoft.Xna.Framework.Graphics.Texture2D texture2d) { CCTexture2D texture = new CCTexture2D(); texture.InitWithTexture(texture2d); CCTextureAtlas textureAtlas = CCTextureAtlas.Create(texture, 128); return textureAtlas; }
public static Cocos2D.CCTexture2D CreateTexture(Stream stream) { PngDecoder png = new PngDecoder(); byte[] colors = png.Decode(stream); CCTexture2D cctexture = new CCTexture2D(); cctexture.InitWithRawData<byte>(colors, Microsoft.Xna.Framework.Graphics.SurfaceFormat.Color, png.Width, png.Height, false); return cctexture; }
private void TextureReInit() { m_pRenderTarget2D = null; m_pTexture = null; if (m_pSprite != null) { m_pSprite.RemoveFromParent(); m_pSprite = null; } MakeTexture(); }
/* * init with CCTexture2D */ public bool InitWithTexture(CCTexture2D tex, int capacity) { TextureAtlas.InitWithTexture(tex, capacity); // no lazy alloc in this node m_pChildren = new CCRawList<CCNode>(capacity); m_tBlendFunc = CCBlendFunc.AlphaBlend; return true; }
public static void InitializeTTFAtlas(int width, int height) { m_nWidth = width; m_nHeight = height; m_nDepth = 4; m_pTexture = new CCTexture2D(); m_pData = new int[width * height]; m_pNodes.Clear(); m_pNodes.Add(new ivec3() { x = 1, y = 1, z = m_nWidth - 2 }); }
public SpriteBatchNodeNewTexture() { TouchEnabled = true; CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); m_texture1 = batch.Texture; m_texture2 = CCTextureCache.SharedTextureCache.AddImage("Images/grossini_dance_atlas-mono"); for (int i = 0; i < 30; i++) addNewSprite(); }
/* * init with CCTexture2D */ public bool InitWithTexture(CCTexture2D tex, int capacity) { TextureAtlas.InitWithTexture(tex, capacity); // no lazy alloc in this node m_pChildren = new CCRawList<CCNode>(capacity); m_tBlendFunc.Source = CCMacros.CCDefaultSourceBlending; m_tBlendFunc.Destination = CCMacros.CCDefaultDestinationBlending; //setShaderProgram(CCShaderCache::sharedShaderCache().programForKey(kCCShader_PositionTextureColor)); return true; }
public SpriteNewTexture() { base.TouchEnabled = true; CCNode node = new CCNode (); AddChild(node, 0, (int)kTags.kTagSpriteBatchNode); m_texture1 = CCTextureCache.SharedTextureCache.AddImage("Images/grossini_dance_atlas"); m_texture2 = CCTextureCache.SharedTextureCache.AddImage("Images/grossini_dance_atlas-mono"); m_usingTexture1 = true; for (int i = 0; i < 30; i++) addNewSprite(); }
private void MakeTexture() { m_pTexture = new CCTexture2D(); m_pTexture.OnReInit = TextureReInit; m_pTexture.IsAntialiased = false; m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(m_Width, m_Height, m_ColorFormat, m_DepthFormat, m_Usage); m_pTexture.InitWithTexture(m_pRenderTarget2D, m_ColorFormat, true, false); m_bFirstUsage = true; m_pSprite = new CCSprite(m_pTexture); //m_pSprite.scaleY = -1; m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend; AddChild(m_pSprite); }
protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage) { w = (int)Math.Ceiling(w * CCMacros.CCContentScaleFactor()); h = (int)Math.Ceiling(h * CCMacros.CCContentScaleFactor()); m_pTexture = new CCTexture2D(); m_pTexture.IsAntialiased = false; m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage); m_pTexture.InitWithTexture(m_pRenderTarget2D, colorFormat, true, false); m_bFirstUsage = true; m_pSprite = new CCSprite(m_pTexture); //m_pSprite.scaleY = -1; m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend; AddChild(m_pSprite); return true; }
protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage) { w = (w * CCMacros.CCContentScaleFactor()); h = (h * CCMacros.CCContentScaleFactor()); m_pTexture = new CCTexture2D(); m_pTexture.SetAliasTexParameters(); m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage); m_pTexture.InitWithTexture(m_pRenderTarget2D); m_bFirstUsage = true; m_pSprite = new CCSprite(m_pTexture); //m_pSprite.scaleY = -1; m_pSprite.BlendFunc = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); // OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); AddChild(m_pSprite); return true; }
protected virtual bool InitWithTexture(CCTexture2D tex, int capacity) { m_blendFunc = CCBlendFunc.AlphaBlend; m_pobTextureAtlas = new CCTextureAtlas(); if (capacity == 0) { capacity = kDefaultSpriteBatchCapacity; } ContentSize= tex.ContentSize; // @@ TotallyEvil - contentSize should return the size of the sprite sheet m_pobTextureAtlas.InitWithTexture(tex, capacity); UpdateBlendFunc(); // no lazy alloc in this node m_pChildren = new CCRawList<CCNode>(capacity); m_pobDescendants = new CCRawList<CCSprite>(capacity); return true; }
private void updateTexture() { CCTexture2D tex; // Dump the old one if (Texture != null) { Texture.Dispose(); } // let system compute label's width or height when its value is 0 // refer to cocos2d-x issue #1430 tex = new CCTexture2D(); tex.InitWithString(m_pString, CCMacros.CCSizePointsToPixels(m_tDimensions), m_hAlignment, m_vAlignment, m_pFontName, m_fFontSize * CCMacros.CCContentScaleFactor()); Texture = tex; CCRect rect = CCRect.Zero; rect.Size = m_pobTexture.ContentSize; SetTextureRect(rect); }
public void AddSpriteFramesWithDictionary(PlistDictionary pobDictionary, CCTexture2D pobTexture) { AddSpriteFramesWithDictionary(pobDictionary, pobTexture, string.Empty); }
protected virtual bool InitWithString(string theString, string fntFile, CCSize dimentions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, CCPoint imageOffset, CCTexture2D texture) { Debug.Assert(m_pConfiguration == null, "re-init is no longer supported"); Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null), "Invalid params for CCLabelBMFont"); if (!String.IsNullOrEmpty(fntFile)) { CCBMFontConfiguration newConf = FNTConfigLoadFile(fntFile); if (newConf == null) { CCLog.Log("CCLabelBMFont: Impossible to create font. Please check file: '{0}'", fntFile); return false; } m_pConfiguration = newConf; m_sFntFile = fntFile; if (texture == null) { try { texture = CCTextureCache.SharedTextureCache.AddImage(m_pConfiguration.AtlasName); } catch (Exception) { // Try the 'images' ref location just in case. try { texture = CCTextureCache.SharedTextureCache.AddImage(System.IO.Path.Combine("images", m_pConfiguration .AtlasName)); } catch (Exception) { // Lastly, try <font_path>/images/<font_name> string dir = System.IO.Path.GetDirectoryName(m_pConfiguration.AtlasName); string fname = System.IO.Path.GetFileName(m_pConfiguration.AtlasName); string newName = System.IO.Path.Combine(System.IO.Path.Combine(dir, "images"), fname); texture = CCTextureCache.SharedTextureCache.AddImage(newName); } } } } else { texture = new CCTexture2D(); } if (String.IsNullOrEmpty(theString)) { theString = String.Empty; } if (base.InitWithTexture(texture, theString.Length)) { m_tDimensions = dimentions; m_pHAlignment = hAlignment; m_pVAlignment = vAlignment; m_cDisplayedOpacity = m_cRealOpacity = 255; m_tDisplayedColor = m_tRealColor = CCTypes.CCWhite; m_bCascadeOpacityEnabled = true; m_bCascadeColorEnabled = true; m_obContentSize = CCSize.Zero; m_bIsOpacityModifyRGB = m_pobTextureAtlas.Texture.HasPremultipliedAlpha; AnchorPoint = new CCPoint(0.5f, 0.5f); m_tImageOffset = imageOffset; m_pReusedChar = new CCSprite(); m_pReusedChar.InitWithTexture(m_pobTextureAtlas.Texture, CCRect.Zero, false); m_pReusedChar.BatchNode = this; SetString(theString, true); return true; } return false; }
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; } } }
protected virtual bool InitWithSize(CCGridSize gridSize, CCSize size) { //ulong POTWide = ccNextPOT((uint) size.width); //ulong POTHigh = ccNextPOT((uint) size.width); ulong potWide = (uint) size.Width; ulong potHigh = (uint) size.Height; // we only use rgba8888 var format = CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888; var pTexture = new CCTexture2D(); pTexture.InitWithData(null, format, (uint) potWide, (uint) potHigh, size); InitWithSize(gridSize, pTexture, false); return true; }
/// <summary> /// /// </summary> /// <param name="pszPlist"></param> /// <param name="pobTexture"></param> /// <param name="framePrefix"></param> /// <returns>The framePrefix parameter</returns> public string AddSpriteFramesWithFile(string pszPlist, CCTexture2D pobTexture, string framePrefix) { PlistDocument document = CCContentManager.SharedContentManager.Load<PlistDocument>(pszPlist); PlistDictionary dict = document.Root.AsDictionary; AddSpriteFramesWithDictionary(dict, pobTexture, framePrefix); return (framePrefix); }
public static CCMotionStreak Create(float fade, float minSeg, float stroke, CCColor3B color, CCTexture2D texture) { var pRet = new CCMotionStreak(); pRet.InitWithFade(fade, minSeg, stroke, color, texture); return(pRet); }
public static CCMotionStreak Create(float fade, float minSeg, float stroke, CCColor3B color, CCTexture2D texture) { var pRet = new CCMotionStreak(); pRet.InitWithFade(fade, minSeg, stroke, color, texture); return pRet; }
public bool InitWithFade(float fade, float minSeg, float stroke, CCColor3B color, CCTexture2D texture) { Position = CCPoint.Zero; AnchorPoint = CCPoint.Zero; IgnoreAnchorPointForPosition = true; m_bStartingPositionInitialized = false; m_tPositionR = CCPoint.Zero; m_bFastMode = true; m_fMinSeg = (minSeg == -1.0f) ? stroke / 5.0f : minSeg; m_fMinSeg *= m_fMinSeg; m_fStroke = stroke; m_fFadeDelta = 1.0f / fade; m_uMaxPoints = (int) (fade * 60.0f) + 2; m_uNuPoints = 0; m_pPointState = new float[m_uMaxPoints]; m_pPointVertexes = new CCPoint[m_uMaxPoints]; m_pVertices = new CCV3F_C4B_T2F[(m_uMaxPoints + 1) * 2]; // Set blend mode m_tBlendFunc.Source = CCOGLES.GL_SRC_ALPHA; m_tBlendFunc.Destination = CCOGLES.GL_ONE_MINUS_SRC_ALPHA; // shader program // setShaderProgram(CCShaderCache.sharedShaderCache().programForKey(kCCShader_PositionTextureColor)); Texture = texture; Color = color; ScheduleUpdate(); return true; }
public void AddSpriteFrameWithTexture(CCTexture2D pobTexture, CCRect rect) { CCSpriteFrame pFrame = new CCSpriteFrame(pobTexture, rect); AddSpriteFrame(pFrame); }
public bool InitWithFade(float fade, float minSeg, float stroke, CCColor3B color, CCTexture2D texture) { Position = CCPoint.Zero; AnchorPoint = CCPoint.Zero; IgnoreAnchorPointForPosition = true; m_bStartingPositionInitialized = false; m_tPositionR = CCPoint.Zero; m_bFastMode = true; m_fMinSeg = (minSeg == -1.0f) ? stroke / 5.0f : minSeg; m_fMinSeg *= m_fMinSeg; m_fStroke = stroke; m_fFadeDelta = 1.0f / fade; m_uMaxPoints = (int)(fade * 60.0f) + 2; m_uNuPoints = 0; m_pPointState = new float[m_uMaxPoints]; m_pPointVertexes = new CCPoint[m_uMaxPoints]; m_pVertices = new CCV3F_C4B_T2F[(m_uMaxPoints + 1) * 2]; // Set blend mode m_tBlendFunc = CCBlendFunc.NonPremultiplied; Texture = texture; Color = color; ScheduleUpdate(); return(true); }
public void AddSpriteFramesWithFile(string pszPlist, CCTexture2D pobTexture) { PlistDocument document = CCContentManager.SharedContentManager.Load<PlistDocument>(pszPlist); PlistDictionary dict = document.Root.AsDictionary; AddSpriteFramesWithDictionary(dict, pobTexture); }
/// <summary> /// /// </summary> /// <param name="pszPlist"></param> /// <returns>The scope parameter derived from the pszPlist parameter.</returns> public string AddSpriteFramesWithFile(string pszPlist) { string path = CCFileUtils.FullPathFromRelativePath(pszPlist); //Dictionary<string, Object> dict = CCFileUtils.dictionaryWithContentsOfFile(pszPath); PlistDocument document = null; try { document = CCApplication.SharedApplication.Content.Load <PlistDocument>(path); } catch (System.Exception) { string xml = Cocos2D.Framework.CCContent.LoadContentFile(path); if (xml != null) { document = new PlistDocument(xml); } } if (document == null) { throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the particle definition file from " + path)); } PlistDictionary dict = document.Root.AsDictionary; string texturePath = ""; PlistDictionary metadataDict = dict.ContainsKey("metadata") ? dict["metadata"].AsDictionary : null; string framePrefix = string.Empty; if (metadataDict != null) { // try to read texture file name from meta data if (metadataDict.ContainsKey("textureFileName")) { texturePath = metadataDict["textureFileName"].AsString; framePrefix = ExtractPrefix(texturePath); } } if (!string.IsNullOrEmpty(texturePath)) { // build texture path relative to plist file texturePath = CCFileUtils.FullPathFromRelativeFile(texturePath, path); } else { // build texture path by replacing file extension texturePath = path; // remove .xxx texturePath = CCFileUtils.RemoveExtension(texturePath); CCLog.Log("cocos2d: CCSpriteFrameCache: Trying to use file {0} as texture", texturePath); } CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(texturePath); if (pTexture != null) { AddSpriteFramesWithDictionary(dict, pTexture, framePrefix); } else { CCLog.Log("cocos2d: CCSpriteFrameCache: Couldn't load texture"); } return(framePrefix); }
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; } } }
/// <summary> /// /// </summary> /// <param name="pszPlist"></param> /// <param name="pobTexture"></param> /// <returns>The scope parameter derived from the pszPlist parameter.</returns> public string AddSpriteFramesWithFile(string pszPlist, CCTexture2D pobTexture) { string scope = ExtractPrefix(pszPlist); AddSpriteFramesWithFile(pszPlist, pobTexture, scope); return (scope); }
/* * creation with CCTexture2D */ public CCParticleBatchNode (CCTexture2D tex) : this(tex, kCCParticleDefaultCapacity) { }
public string AddSpriteFramesWithFile(Stream plist, CCTexture2D pobTexture, string framePrefix) { PlistDocument document = new PlistDocument(); try { document.LoadFromXmlFile(plist); } catch (Exception) { throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the particle definition file from stream")); } PlistDictionary dict = document.Root.AsDictionary; AddSpriteFramesWithDictionary(dict, pobTexture, framePrefix); return (framePrefix); }
public CCParticleBatchNode (CCTexture2D tex, int capacity /* = kCCParticleDefaultCapacity*/) { InitWithTexture(tex, capacity); }
public override void UpdateAtlasValues() { int n = m_sString.Length; CCTexture2D texture = m_pTextureAtlas.Texture; float textureWide = texture.PixelsWide; float textureHigh = texture.PixelsHigh; float itemWidthInPixels = m_uItemWidth * CCMacros.CCContentScaleFactor(); float itemHeightInPixels = m_uItemHeight * CCMacros.CCContentScaleFactor(); for (int i = 0; i < n; i++) { var a = (char)(m_sString[i] - m_cMapStartChar); float row = (a % m_uItemsPerRow); float col = (a / m_uItemsPerRow); #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL // Issue #938. Don't use texStepX & texStepY float left = (2 * row * itemWidthInPixels + 1) / (2 * textureWide); float right = left + (itemWidthInPixels * 2 - 2) / (2 * textureWide); float top = (2 * col * itemHeightInPixels + 1) / (2 * textureHigh); float bottom = top + (itemHeightInPixels * 2 - 2) / (2 * textureHigh); #else float left = row * itemWidthInPixels / textureWide; float right = left + itemWidthInPixels / textureWide; float top = col * itemHeightInPixels / textureHigh; float bottom = top + itemHeightInPixels / textureHigh; #endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL CCV3F_C4B_T2F_Quad quad; quad.TopLeft.TexCoords.U = left; quad.TopLeft.TexCoords.V = top; quad.TopRight.TexCoords.U = right; quad.TopRight.TexCoords.V = top; quad.BottomLeft.TexCoords.U = left; quad.BottomLeft.TexCoords.V = bottom; quad.BottomRight.TexCoords.U = right; quad.BottomRight.TexCoords.V = bottom; quad.BottomLeft.Vertices.X = i * m_uItemWidth; quad.BottomLeft.Vertices.Y = 0.0f; quad.BottomLeft.Vertices.Z = 0.0f; quad.BottomRight.Vertices.X = i * m_uItemWidth + m_uItemWidth; quad.BottomRight.Vertices.Y = 0.0f; quad.BottomRight.Vertices.Z = 0.0f; quad.TopLeft.Vertices.X = i * m_uItemWidth; quad.TopLeft.Vertices.Y = m_uItemHeight; quad.TopLeft.Vertices.Z = 0.0f; quad.TopRight.Vertices.X = i * m_uItemWidth + m_uItemWidth; quad.TopRight.Vertices.Y = m_uItemHeight; quad.TopRight.Vertices.Z = 0.0f; quad.TopLeft.Colors = quad.TopRight.Colors = quad.BottomLeft.Colors = quad.BottomRight.Colors = new CCColor4B(_displayedColor.R, _displayedColor.G, _displayedColor.B, _displayedOpacity); m_pTextureAtlas.UpdateQuad(ref quad, i); } }
public void RemoveSpriteFramesFromTexture(CCTexture2D texture) { var keysToRemove = new List<string>(); foreach (string key in m_pSpriteFrames.Keys) { CCSpriteFrame frame = m_pSpriteFrames[key]; if (frame != null && (frame.Texture.Name == texture.Name)) { keysToRemove.Add(key); } } foreach (string key in keysToRemove) { m_pSpriteFrames.Remove(key); } }
public CCLightningStreak(CCPoint start, CCPoint end, float sway, float fadeTime, float minSegLength, float streakWidth, CCColor3B color, CCTexture2D texture) : base(fadeTime, minSegLength, streakWidth, color, texture) { _Track = new CCLightningTrack(start, end); _Track.Sway = sway; }