public static void CreateAtlas() { SpriteNames.Clear(); SpriteTextures.Clear(); foreach (MapThemeMetaData meta in ThemeManager.Instance.Themes.Values) { if (meta == null) { continue; } for (var i = 0; i < AssetNames.Length; i++) { string assetName = i < 2 ? string.Concat(meta.name, "_", AssetNames[i]) : AssetNames[i]; string spriteName = string.Concat(meta.assetRef.fullName, assetName); spriteName = Regex.Replace(spriteName, @"(\s+|@|&|'|\(|\)|<|>|#|"")", ""); var tex = meta.assetRef.package.Find(assetName)?.Instantiate <Texture2D>(); if (tex == null) { continue; } Texture2D spriteTex = tex.ScaledCopy(64.0f / tex.height); Object.Destroy(tex); spriteTex.Apply(); SpriteNames.Add(spriteName); SpriteTextures.Add(spriteTex); } } Atlas = ResourceUtils.CreateAtlas("ThemesAtlas", SpriteNames.ToArray(), SpriteTextures.ToArray()); }
public void LoadContent() { // Load animated textures. SpriteTextures.Add(Level.Content.Load <Texture2D>("Sprites/Player/player")); Animation anim = new Animation(); anim.LoadAnimation("Idle", 0, new List <int> { 0, 11, 0, 12 }, 7, true); SpriteAnimations.Add("Idle", anim); anim = new Animation(); anim.LoadAnimation("Walking", 0, new List <int> { 0, 1, 2, 3, 4, 5, 6 }, 7, true); SpriteAnimations.Add("Walking", anim); anim = new Animation(); anim.LoadAnimation("Jump", 0, new List <int> { 7, 8, 9, 10, 9, 8, 7 }, 20, false); anim.AnimationCallBack(JumpAnimEnd); SpriteAnimations.Add("Jump", anim); // Calculate bounds within texture size. // subtract 4 from width and height to remove a 2px buffer // around the player. int width = FrameWidth - 4; int left = (FrameWidth - width) / 2; int height = FrameHeight - 4; int top = FrameHeight - height; localBounds = new Rectangle(left, top, width, height); anim = new Animation(); anim.LoadAnimation("Dead", 0, new List <int> { 13, 14, 15 }, 6, false); anim.AnimationCallBack(DeadAnimEnd); SpriteAnimations.Add("Dead", anim); }
public MultiSpriteTexture2D(IEnumerable <ISpriteTexture> spriteTextures) { SpriteTextures = spriteTextures.ToList(); if (spriteTextures == null) { throw new ArgumentNullException("spriteTextures"); } if (!SpriteTextures.Any()) { throw new ArgumentException("No sprite textures", "spriteTextures"); } }
/// <summary> /// Mod_LoadSpriteModel /// </summary> private void LoadSprite(SpriteModelData mod, Byte[] buffer) { mod.Load(mod.Name, buffer, (name, buf, width, height) => { var texture = (Renderer.OpenGL.Textures.GLTexture)BaseTexture.FromBuffer(Host.Video.Device, name, buf, width, height, hasMipMap: true, hasAlpha: true); SpriteTextures.Add(texture); return(texture.GLDesc.TextureNumber); }); }
/// <summary> /// Mod_LoadSpriteModel /// </summary> public void LoadSpriteModel(SpriteModelData mod, Byte[] buffer) { mod.Load(mod.Name, buffer, (n, b, w, h) => { var texture = (Renderer.OpenGL.Textures.GLTexture)BaseTexture.FromBuffer(Host.Video.Device, n, b, w, h, true, true); SpriteTextures.Add(texture); return(texture.GLDesc.TextureNumber); }); }
public void LoadContent(string _enemy) { string enemyString = string.Empty; switch (_enemy) { case "e": enemyString = "Sprites/Enemies/muffinman"; break; default: enemyString = "Sprites/Enemies/muffinman"; break; } // Load animated textures. Texture2D tex = Level.Content.Load <Texture2D>(enemyString); if (!SpriteTextures.Contains(tex)) { SpriteTextures.Add(tex); } Animation anim = new Animation(); anim.LoadAnimation("Walk", 0, new List <int> { 0, 1 }, 4, true); SpriteAnimations.Add("Walk", anim); anim = new Animation(); anim.LoadAnimation("Dead", 0, new List <int> { 2, 3, 4, 5 }, 36, false); anim.AnimationCallBack(DeadAnimEnd); SpriteAnimations.Add("Dead", anim); // Calculate bounds within texture size. // subtract 10 from width and height to remove a 5px buffer // around the enemy. int width = FrameWidth - 10; int left = (FrameWidth - width) / 2; int height = FrameHeight - 10; int top = FrameHeight - height; localBounds = new Rectangle(left, top, width, height); SpriteAnimations[currentAnim].ResetPlay(); }
public void LoadContent(string _collectable) { string sheetString = string.Empty; switch (_collectable) { case "s": sheetString = "Sprites/Collectables/scribbles"; colorOffset = Color.Black; break; case "S": sheetString = "Sprites/Collectables/scribbles"; colorOffset = Color.Gold; break; default: sheetString = "Sprites/Collectables/scribbles"; colorOffset = Color.White; break; } // Load animated textures. Texture2D tex = Level.Content.Load <Texture2D>(sheetString); if (!SpriteTextures.Contains(tex)) { SpriteTextures.Add(tex); } Animation anim = new Animation(); anim.LoadAnimation("Idle", 0, new List <int> { 0, 1, 2, 3 }, 16, true); SpriteAnimations.Add("Idle", anim); // Calculate bounds within texture size. // subtract 4 from height to remove a 2px buffer // around the collectable. int width = FrameWidth; int left = (FrameWidth - width) / 2; int height = FrameHeight - 4; int top = FrameHeight - height; localBounds = new Rectangle(left, top, width, height); SpriteAnimations[currentAnim].ResetPlay(); }
public void LoadContent(string _collectable) { string sheetString = string.Empty; switch (_collectable) { case "s": sheetString = "Sprites//Collectable/scribbles"; colorOffset = Color.Black; pointsAwarded = 500; break; case "S": sheetString = "Sprites/Collectable/scribbles"; colorOffset = Color.Gold; pointsAwarded = 1000; break; default: sheetString = "Sprites/Collectable/scribbles"; colorOffset = Color.White; break; } Texture2D tex = Level.Content.Load <Texture2D>(sheetString); if (!SpriteTextures.Contains(tex)) { SpriteTextures.Add(tex); } Animation anim = new Animation(); anim.LoadAnimation("Idle", 0, new List <int> { 0, 1, 2, 3 }, 16, true); SpriteAnimations.Add("Idle", anim); int width = FrameWidth; int left = (FrameWidth - width) / 2; int height = FrameHeight - 4; int top = FrameHeight - height; localBounds = new Rectangle(left, top, width, height); SpriteAnimations[currentAnim].ResetPlay(); }
public void LoadContent() { // Load animated textures. SpriteTextures.Add(Level.Content.Load <Texture2D>("Sprites/Player/player")); Animation anim = new Animation(); anim.LoadAnimation("Idle", 0, new List <int> { 0, 11, 0, 12 }, 7, true); SpriteAnimations.Add("Idle", anim); anim = new Animation(); anim.LoadAnimation("Walking", 0, new List <int> { 9, 12, 9, 10 }, 7, true); SpriteAnimations.Add("Walking", anim); anim = new Animation(); anim.LoadAnimation("Jump", 0, new List <int> { 7, 8, 9, 10, 9, 8, 7 }, 20, false); anim.AnimationCallBack(JumpAnimEnd); SpriteAnimations.Add("Jump", anim); anim = new Animation(); anim.LoadAnimation("Dead", 0, new List <int> { 13, 14, 15 }, 6, false); anim.AnimationCallBack(DeadAnimEnd); SpriteAnimations.Add("Dead", anim); int width = FrameWidth - 4; int left = (FrameWidth - width) / 2; int height = FrameHeight - 4; int top = FrameHeight - height; localBounds = new Rectangle(left, top, width, height); }