protected override void Initialize() { //TODO: Remove this after testing! DrawEngine2d.ClearColor = Colors.Blue; //EnableDebugInfo(); String shipSprite = "/Application/TwinStickShooter/Images/Ship64.png"; Texture2dPlus t2d = new Texture2dPlus(DrawEngine2d, TextureCachePolicy.DisposeAfterLastUse, shipSprite); TiledTexture tt = new TiledTexture(DrawEngine2d, TextureCachePolicy.DisposeAfterLastUse, shipSprite, t2d); tt.CreateColumnIndex(1); LayerBase l2 = DrawEngine2d.GetOrCreateWorldLayer(1); SpriteGroup sssg = new SpriteGroup(l2, tt); SpriteGroupItem sss1 = new SpriteGroupItem(sssg, new TiledTextureIndex(0)); sss1.SetPositionFromCenter(new Coordinate2(32f, 32f)); SpriteGroupItem sss2 = new SpriteGroupItem(sssg, new TiledTextureIndex(0)); sss2.SetPositionFromCenter(new Coordinate2(96f, 32f)); //sss2.Rotation = 45.0f; Texture2dPlus testT2d = DrawEngine2d.GetTexture(DebugFont.TextureKey); TiledTexture ttTest = new TiledTexture(DrawEngine2d, TextureCachePolicy.DisposeAfterLastUse, "test", testT2d); ttTest.CreateColumnIndex(1); SpriteGroup testSG = new SpriteGroup(l2, ttTest); SpriteGroupItem testSS = new SpriteGroupItem(testSG, new TiledTextureIndex(0)); testSS.Position = new Coordinate2(32f, 200f); LayerBase debugOverlay = DrawEngine2d.GetOrCreateScreenLayer(2); _DebugTextLabel = new DebugLabel(debugOverlay); _DebugTextLabel.Text = "I"; _DebugTextLabel.Position = new Coordinate2(100.0f, 100.0f); }
public static void CreateFont(DrawEngine2d drawEngine2d) { //These two should be in sync all the time. //They should be unified by combining the upper and lower data // into a single UInt and kept as a single dict. var upper = new Dictionary<Char, UInt32>(); var lower = new Dictionary<Char, UInt32>(); PopulateDicts(ref upper, ref lower); Int32 textureWidth = MaxTextureCharCapacity * FontWidth; Int32 textureHeight = FontHeight; Byte[] texturePixels = new Byte[textureWidth * textureHeight]; //This loop references only one of the two glyph dicts but // that is just a convenience. The data from both will be // used during the loop. foreach(Char c in upper.Keys) DecodePixelData(ref upper, ref lower, ref texturePixels, c, textureWidth); Texture2dPlus texture = new Texture2dPlus(drawEngine2d,TextureCachePolicy.KeepAlways, TextureKey, textureWidth, textureHeight, PixelFormat.Luminance); texture.SetPixels(0, texturePixels, PixelFormat.Luminance); texture.SetFilter(TextureFilterMode.Nearest, TextureFilterMode.Nearest, TextureFilterMode.Nearest); TiledTexture tiledTexture = new TiledTexture(drawEngine2d,TextureCachePolicy.KeepAlways, DebugFont.TextureKey, texture); tiledTexture.CreateColumnIndex(MaxTextureCharCapacity); }
private void CleanupTiledTextureManager() { //Textures TiledTexture[] cleanup = new TiledTexture[TiledTextures.Values.Count]; TiledTextures.Values.CopyTo(cleanup, 0); foreach(TiledTexture t in cleanup) t.Dispose(); TiledTextures.Clear(); TiledTextures = null; //Cache TiledTextureCachePolicies.Clear(); TiledTextureCachePolicies = null; //Users foreach(List<DrawableBase> list in TiledTextureUsers.Values) list.Clear(); TiledTextureUsers.Clear(); TiledTextureUsers = null; }
internal void RemoveTexture2dPlusUser(String key, TiledTexture user) { if(String.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(); if(user == null) throw new ArgumentNullException(); if(!Texture2dPlusUsers.ContainsKey(key)) throw new ArgumentException("Attempt to remove a user from an unknown key."); if(Texture2dPlusUsers[key] == null) throw new ArgumentException("Attempt to remove an unknown user."); if(!Texture2dPlusUsers[key].Contains(user)) throw new ArgumentException("Attempt to remove an unknown user."); Texture2dPlusUsers[key].Remove(user); //Let the cache policy decide what to do. ApplyTexture2dPlusCachePolicyForRemovalOfUser(key); }
internal void RegisterTiledTexture(String key, TiledTexture texture, TextureCachePolicy cachePolicy) { if(String.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(); if(texture == null) throw new ArgumentNullException(); if(TiledTextures.ContainsKey(key)) throw new ArgumentException("Attempt to register duplicate key."); TiledTextures.Add(key, texture); TiledTextureCachePolicies.Add(key, cachePolicy); TiledTextureUsers.Add(key, new List<DrawableBase>()); }
internal void AddTexture2dPlusUser(String key, TiledTexture user) { if(String.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(); if(user == null) throw new ArgumentNullException(); if(!Texture2dPlusUsers.ContainsKey(key)) throw new ArgumentException("Attempt to add a user to an unknown key."); if(Texture2dPlusUsers[key] == null) Texture2dPlusUsers[key] = new List<TiledTexture>(); if(Texture2dPlusUsers[key].Contains(user)) throw new ArgumentException("Attempt to register a duplicate user."); Texture2dPlusUsers[key].Add(user); }
private void InitializeTiledTexture(TiledTexture tiledTexture) { if(tiledTexture == null) throw new ArgumentNullException(); TiledTexture = tiledTexture; RegisterAsUserOfTiledTexture(); }
private void InitializeCustom(TiledTexture tiledTexture) { InitializeTiledTexture(tiledTexture); InitializeSprites(); InitializeVertices(); InitializeIndices(); InitializeTextureCoordinates(); InitializeColor(); InitializeVertexBuffer(); InitializeShaderProgram(); InitializeScalingMatrixCache(); InitializeRotationMatrixCache(); InitializeTransformationMatrixCache(); }
public SpriteGroup(LayerBase layer, TiledTexture tiledTexture) : base(layer) { InitializeCustom(tiledTexture); }