public void Test_AddTexture_1() { var spr = new Sprite (64, 64); spr.AddTexture (new Texture ("abstract7.png")); spr.AddTexture (new Texture ("image2x2.png")); Assert.AreEqual (64, spr.Width); Assert.AreEqual (64, spr.Height); Assert.AreEqual (2, spr.TextureCount); Assert.AreEqual ("abstract7.png", spr.GetTexture(0).Name); Assert.AreEqual ("image2x2.png", spr.GetTexture(1).Name); }
public static Node Create(Vector3 pos) { var cmp = new MyComponent (); var spr = new Sprite (480, 300); spr.AddTexture (new Texture ("media/Vanity.jpg")); spr.AddTexture (new Texture ("media/Tanks.png")); spr.AddTexture (new Texture ("media/TatamiRoom.png")); spr.AutoScale = true; Console.WriteLine ("tex = " + spr.GetTexture (0)); Console.WriteLine ("spr = " + spr); var col = new CollisionObject(); col.Shape = new BoxShape(spr.Width/2, spr.Height/2, 100); col.SetOffset (spr.Width/2, spr.Height/2, 0); var ctr = new AnimationController (); var node = new Node (); node.Attach (cmp); node.Attach (spr); node.Attach (col); node.Attach (ctr); node.Translation = pos; var clip = new SoundClip ("Sound"); clip.AddTrack (new SoundEffectTrack ("media/PinPon.wav")); node.UserData.Add (clip.Name, clip); return node; }
public TitleMenuItem(string name) : base ( name, Utility.Fonts["blocks"], Sprite.GetTexture("titleMenuSelected"), Sprite.GetTexture("titleMenuUnselected"), Sprite.GetTexture("titleMenuDisabled") ) { }
public static void DrawSprite(Sprite sprite_) { // Draw a sprite from its' variables data // ================ Rectangle scale = new Rectangle((int)sprite_.GetPosition().X, (int)sprite_.GetPosition().Y, (int)(sprite_.GetWidth() * sprite_.GetScale().X), (int)(sprite_.GetHeight() * sprite_.GetScale().Y)); m_spriteBatch.Draw(sprite_.GetTexture(), scale, null, Color.White, sprite_.GetRotationRadians(), sprite_.GetOrigin(), SpriteEffects.None, 0); }
private void PopulateTextures() { if (frames == null) { frames = new Texture2D[3]; for (int i = 0; i < 3; i++) { frames[i] = Sprite.GetTexture("bomb" + i); } } }
public override void _Ready() { Sprite = GetNode <Sprite>("Sprite"); ChildCam = GetNode <Camera2D>("Camera2D"); ChildCam.Current = true; SpriteSize = Sprite.GetTexture().GetSize(); var animation = GetNode <AnimationPlayer>("AnimationPlayer"); animation.Play("Idle"); }
public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(Sprite.GetTexture(Active ? "titleMenuSelected" : "titleMenuUnselected"), bounds, Color.White); SpriteFont font = Utility.Fonts["blocks"]; for (int i = 0; i < MaxLength; i++) { Vector2 charPosition = new Vector2(bounds.X + 24 + font.MeasureString("W").X *i, bounds.Y); charPosition.X += (font.MeasureString("W").X - font.MeasureString(text[i].ToString()).X) / 2; spriteBatch.DrawString(font, text[i].ToString(), charPosition, Active && i == index ? Color.LightYellow : Color.Black); } }
public void Update(GameTime gameTime) { _sb.Begin(); foreach (var kvp in _layeredGameObjectList) { foreach (GameObject go in kvp.Value.ToArray()) { if (go != null) { Transform transform = go.transform; Rectangle rect = transform.Rect; Vector2 offset = transform.GetOffset(); rect.X += (int)offset.X; rect.Y += (int)offset.Y; Sprite sprite = go.GetComponent <Sprite>(); if (sprite != null && sprite.GetTexture() != null) { _sb.Draw(sprite.GetTexture(), rect, Color.White); } Label Label = go.GetComponent <Label>(); if (Label != null && Label.Text != null) { Vector2 goPos = new Vector2(transform.Position.X, transform.Position.Y); if (Label.LeftToRight) { _sb.DrawString(Label.Font, Label.Text, goPos + offset + Label.Pos, Label.Color); } else { Vector2 pos = new Vector2(Label.Pos.X - Label.Font.MeasureString(Label.Text).X, Label.Pos.Y); _sb.DrawString(Label.Font, Label.Text, goPos + offset + pos, Label.Color); } } } } } _sb.End(); }
private void PopulateTextures() { if (BgSprite == null) { Texture2D[] frames = new Texture2D[] { Sprite.GetTexture("powerup0"), Sprite.GetTexture("powerup1"), Sprite.GetTexture("powerup2"), Sprite.GetTexture("powerup1"), }; BgSprite = new Sprite(frames, 5); } }
private static void GetSprite() { if (frames == null) { frames = new Texture2D[8]; for (int i = 0; i < 4; i++) { frames[i] = Sprite.GetTexture("explosion" + i); } // Jank, but this prolongs the animation to avoid an issue with // explosions looping in on themselves. // Should eventually fix this properly, but this will do for now for (int i = 0; i < 4; i++) { frames[i + 4] = Sprite.GetTexture("null"); } } }
private void PopulateTextures(string texturePrefix) { if (textures.ContainsKey(GetType())) { return; } Dictionary <Adjacencies, Texture2D> blockTextures = new Dictionary <Adjacencies, Texture2D>(); BitArray bits = new BitArray(4); for (int i = 0; i < 16; i++) { Adjacencies adj = new Adjacencies(bits[0], bits[1], bits[2], bits[3]); StringBuilder sb = new StringBuilder(texturePrefix + "_"); if (!bits[0]) { sb.Append('n'); } if (!bits[2]) { sb.Append('e'); } if (!bits[1]) { sb.Append('w'); } if (!bits[3]) { sb.Append('s'); } bool carry = true; for (int j = 0; j < 4; j++) { bool newbit = bits[j] ^ carry; carry = bits[j] & carry; bits[j] = newbit; } blockTextures.Add(adj, Sprite.GetTexture(sb.ToString())); } textures.Add(GetType(), blockTextures); }
public void Draw(DrawArgs e) { e.SB.Draw(sprite.GetTexture(), Util.GetCenteredRectangle(Util.WorldToScreen(transform.translation, e.device), new Vector2(32f)), sprite.crop, sprite.color); }
/// <summary> /// Returns the sprite texture size /// </summary> /// <returns>Vector2</returns> public Vector2 GetSize() { return(_sprite.GetTexture().GetSize()); }
private void DrawSelection(SpriteBatch spriteBatch) { // Draw Character Rectangle drawBounds = new Rectangle ( Bounds.X + Tile.TILE_SIZE, Bounds.Y + Tile.TILE_SIZE, Tile.TILE_SIZE * 2, Tile.TILE_SIZE * 2 ); spriteBatch.Draw(Sprite.GetTexture(currentItem == SubMenuItems.Character ? "reticle" : "powerup2"), drawBounds, Color.White); spriteBatch.Draw(Sprite.GetTexture($"char{character}_walk_s_1"), drawBounds, Color.White); Vector2 wealthPoint = new Vector2(drawBounds.Center.X - (Utility.Fonts["blocks_small"].MeasureString($"${wealth}").X / 2), Bounds.Y + Tile.TILE_SIZE * 3); spriteBatch.DrawString(Utility.Fonts["blocks_small"], $"${wealth}", wealthPoint, Color.Black); // Draw Name nameEntry.Draw(spriteBatch); // Draw Buy Inventory drawBounds = new Rectangle ( Bounds.X + Tile.TILE_SIZE * 4, Bounds.Y + Tile.TILE_SIZE * 4, Bounds.Width - Tile.TILE_SIZE * 5, Tile.TILE_SIZE ); spriteBatch.Draw(Sprite.GetTexture(currentItem == SubMenuItems.Buy ? "reticle" : "powerup2"), drawBounds, Color.White); buyInventory.Draw(spriteBatch, drawBounds); int currentQuantityOwned = 0; InventoryItem shopItem = buyInventory.GetCurrentItem(); InventoryItem invItem = sellInventory.GetItem(shopItem.Name); if (invItem != null) { currentQuantityOwned = invItem.Quantity; } string costOwned = $"Cost: ${shopItem.Value}\nOwned: {currentQuantityOwned}"; Vector2 drawPoint = new Vector2(drawBounds.Center.X - (Utility.Fonts["blocks_small"].MeasureString(costOwned).X / 2), Bounds.Y + Tile.TILE_SIZE * 5); spriteBatch.DrawString(Utility.Fonts["blocks_small"], costOwned, drawPoint, Color.Black); // Draw Ready button drawBounds = new Rectangle ( Bounds.X + Tile.TILE_SIZE * 4, Bounds.Y + Tile.TILE_SIZE * 8, Bounds.Width - Tile.TILE_SIZE * 8, Tile.TILE_SIZE ); spriteBatch.Draw(Sprite.GetTexture(currentItem == SubMenuItems.Ready ? "reticle" : "powerup2"), drawBounds, Color.White); string ready = currentItem.ToString(); //"Ready"; SpriteFont readyFont = Utility.Fonts["blocks"]; Vector2 readySize = readyFont.MeasureString(ready); Vector2 readyStringPos = new Vector2 ( drawBounds.X + (drawBounds.Width - readySize.X) / 2, drawBounds.Y + (drawBounds.Height - readySize.Y) / 2 ); spriteBatch.DrawString(readyFont, ready, readyStringPos, Color.Black); }