void InitialiseResourceCaches() { ContentManager = new CCContentManager(new GameServiceContainer()); FontAtlasCache = new CCFontAtlasCache(); SpriteFontCache = new CCSpriteFontCache(ContentManager); SpriteFrameCache = new CCSpriteFrameCache(); ParticleSystemCache = new CCParticleSystemCache(Scheduler); TextureCache = new CCTextureCache(Scheduler); AnimationCache = new CCAnimationCache(); // Link new caches to singleton instances // For now, this is required because a layer's resources (e.g. sprite) // may be loaded prior to a gameview being associated with that layer CCContentManager.SharedContentManager = ContentManager; CCFontAtlasCache.SharedFontAtlasCache = FontAtlasCache; CCSpriteFontCache.SharedSpriteFontCache = SpriteFontCache; CCSpriteFrameCache.SharedSpriteFrameCache = SpriteFrameCache; CCParticleSystemCache.SharedParticleSystemCache = ParticleSystemCache; CCTextureCache.SharedTextureCache = TextureCache; CCAnimationCache.SharedAnimationCache = AnimationCache; var serviceProvider = ContentManager.ServiceProvider as GameServiceContainer; serviceProvider.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService); }
protected void InitSpriteFont(string theString, string fntFile, float fontSize, CCSize dimensions, CCLabelFormat labelFormat, CCPoint imageOffset, CCTexture2D texture) { Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null), "Invalid params for CCLabel SpriteFont"); if (!String.IsNullOrEmpty(fntFile)) { try { FontAtlas = CCFontAtlasCache.GetFontAtlasSpriteFont(fntFile, fontSize, imageOffset); } catch {} if (FontAtlas == null) { CCLog.Log("SpriteFont CCLabel: Impossible to create font. Please check file: '{0}'", fntFile); return; } } AnchorPoint = CCPoint.AnchorMiddle; currentLabelType = CCLabelType.SpriteFont; if (String.IsNullOrEmpty(theString)) { theString = String.Empty; } // Initialize the TextureAtlas along with children. var capacity = theString.Length; BlendFunc = CCBlendFunc.AlphaBlend; if (capacity == 0) { capacity = defaultSpriteBatchCapacity; } UpdateBlendFunc(); // no lazy alloc in this node Children = new CCRawList <CCNode>(capacity); Descendants = new CCRawList <CCSprite>(capacity); this.labelDimensions = dimensions; horzAlignment = labelFormat.Alignment; vertAlignment = labelFormat.LineAlignment; IsOpacityCascaded = true; ContentSize = CCSize.Zero; IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha; AnchorPoint = CCPoint.AnchorMiddle; ImageOffset = imageOffset; Text = theString; }
protected void InitBMFont(string theString, string fntFile, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, CCPoint imageOffset, CCTexture2D texture) { Debug.Assert(FontConfiguration == 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)) { try { FontAtlas = CCFontAtlasCache.GetFontAtlasFNT(fntFile, imageOffset); } catch {} if (FontAtlas == null) { CCLog.Log("Bitmap Font CCLabel: Impossible to create font. Please check file: '{0}'", fntFile); return; } } AnchorPoint = CCPoint.AnchorMiddle; FontConfiguration = CCBMFontConfiguration.FontConfigurationWithFile(fntFile); LabelType = CCLabelType.BitMapFont; if (String.IsNullOrEmpty(theString)) { theString = String.Empty; } // Initialize the TextureAtlas along with children. var capacity = theString.Length; BlendFunc = CCBlendFunc.AlphaBlend; if (capacity == 0) { capacity = defaultSpriteBatchCapacity; } UpdateBlendFunc(); // no lazy alloc in this node Children = new CCRawList <CCNode>(capacity); Descendants = new CCRawList <CCSprite>(capacity); this.labelDimensions = dimensions; horzAlignment = hAlignment; vertAlignment = vAlignment; IsOpacityCascaded = true; // We use base here so we do not trigger an update internally. base.ContentSize = CCSize.Zero; IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha; AnchorPoint = CCPoint.AnchorMiddle; ImageOffset = imageOffset; Text = theString; }