public void SetTexture(Texture2D texture, bool repeat = true) { TextureRegion = new TextureRegion2D(texture); _currentFrame = 0; _repeat = repeat; _looped = false; }
//protected override void Initialize() //{ // base.Initialize(); // _graphicsDeviceManager.IsFullScreen = true; // _graphicsDeviceManager.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width; // _graphicsDeviceManager.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height; // _graphicsDeviceManager.ApplyChanges(); //} protected override void LoadContent() { _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480); _font = Content.Load<BitmapFont>("Fonts/courier-new-32"); _camera = new Camera2D(_viewportAdapter); _explosionAnimations = Content.Load<SpriteSheetAnimationGroup>("explosion-animations"); _spriteBatch = new SpriteBatch(GraphicsDevice); _backgroundTexture = Content.Load<Texture2D>("black"); var bulletTexture = Content.Load<Texture2D>("laserBlue03"); var bulletRegion = new TextureRegion2D(bulletTexture); _bulletFactory = new BulletFactory(_entityManager, bulletRegion); SpawnPlayer(_bulletFactory); _meteorFactory = new MeteorFactory(_entityManager, Content); for (var i = 0; i < 13; i++) { _meteorFactory.SpawnNewMeteor(_player.Position); } }
public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth, Rectangle?clippingRectangle = null) { var sourceRectangle = textureRegion.Bounds; if (clippingRectangle.HasValue) { var x = (int)(position.X - origin.X); var y = (int)(position.Y - origin.Y); var width = (int)(textureRegion.Width * scale.X); var height = (int)(textureRegion.Height * scale.Y); var destinationRectangle = new Rectangle(x, y, width, height); sourceRectangle = ClipSourceRectangle(textureRegion.Bounds, destinationRectangle, clippingRectangle.Value); position.X += sourceRectangle.X - textureRegion.Bounds.X; position.Y += sourceRectangle.Y - textureRegion.Bounds.Y; if (sourceRectangle.Width <= 0 || sourceRectangle.Height <= 0) { return; } } spriteBatch.Draw(textureRegion.Texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); }
public HUDDifficultyButton(int depth, FractionDifficulty diff, HUDDifficultyButtonMode mode) { Depth = depth; difficulty = diff; icon = FractionDifficultyHelper.GetIcon(diff); switch (mode) { case HUDDifficultyButtonMode.DEACTIVATED: BackgroundColor = FlatColors.ButtonHUD; ForegroundColor = FlatColors.BackgroundHUD; break; case HUDDifficultyButtonMode.UNLOCKANIMATION: BackgroundColor = FlatColors.ButtonHUD; ForegroundColor = GDColors.GetColorForDifficulty(diff); AddHUDOperation(new HUDDifficultyButtonGainOperation()); AddHUDOperation(new HUDBlinkingDifficultyButtonIconOperation()); break; case HUDDifficultyButtonMode.ACTIVATED: BackgroundColor = FlatColors.BackgroundHUD2; ForegroundColor = GDColors.GetColorForDifficulty(diff); AddHUDOperation(new HUDBlinkingDifficultyButtonIconOperation()); break; } }
public GuiTextureRegionDrawable(TextureRegion2D region) { _region = region; DesiredSize = new Size(_region.Width, _region.Height); Color = Color.White; }
public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { var sourceRectangle = textureRegion.Bounds; spriteBatch.Draw(textureRegion.Texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); }
public BitmapFontRegion(TextureRegion2D textureRegion, char character, int xOffset, int yOffset, int xAdvance) { TextureRegion = textureRegion; Character = character; XOffset = xOffset; YOffset = yOffset; XAdvance = xAdvance; }
private void RenderOrthogonal(TiledTile tile, TextureRegion2D region) { // not exactly sure why we need to compensate 1 pixel here. Could be a bug in MonoGame? var tx = tile.X*(_map.TileWidth - 1); var ty = tile.Y*(_map.TileHeight - 1); _spriteBatch.Draw(region, new Rectangle(tx, ty, region.Width, region.Height), Color.White); }
public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Vector2 position, Color color) { var sourceRectangle = textureRegion.Bounds; spriteBatch.Draw(textureRegion.Texture, position, sourceRectangle, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0); }
public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth, RectangleF?clippingRectangle = null) { if (textureRegion.Bounds.IsVisible(ref position, origin, scale, clippingRectangle, out RectangleF srcRect)) { //System.Console.WriteLine(srcRect); spriteBatch.Draw(textureRegion.Texture, position, srcRect, color, rotation, origin, scale, effects, layerDepth); } }
public TextureRegion2D CreateRegion(string name, int x, int y, int width, int height) { if (_regionMap.ContainsKey(name)) throw new InvalidOperationException("Region {0} already exists in the texture atlas"); var region = new TextureRegion2D(Texture, x, y, width, height); _regionMap.Add(name, region); return region; }
public Spaceship(TextureRegion2D textureRegion, IBulletFactory bulletFactory) { _bulletFactory = bulletFactory; _sprite = new Sprite(textureRegion) { Scale = Vector2.One * 0.5f, Position = new Vector2(400, 240) }; _boundingCircle = new CircleF(_sprite.Position, 20); }
public Laser(TextureRegion2D textureRegion, Vector2 velocity) { _timeToLive = 1.0f; _sprite = new Sprite(textureRegion) { Scale = Vector2.One*0.5f }; Velocity = velocity; }
public RenderData(Midgard midgard, Entity entity, ContentManager manager) { var text = manager.Load<Texture2D>("roguelikeChar_transparent"); TextureRegion2D region = new TextureRegion2D(text, 0, 0, 16, 16); _sprite = new Sprite(region); _sprite.Scale = new Vector2(1, 1); CreatePhysics(midgard, entity); }
public Meteor(TextureRegion2D textureRegion, Vector2 position, Vector2 velocity, float rotationSpeed, int size) { _sprite = new Sprite(textureRegion); _boundingCircle = new CircleF(_sprite.Position, _radius * size); Position = position; Velocity = velocity; RotationSpeed = rotationSpeed; HealthPoints = 1; Size = size; }
public GuiPatchDrawable(TextureRegion2D textureRegion, int leftPadding, int topPadding, int rightPadding, int bottomPadding, Color color) { TextureRegion = textureRegion; LeftPadding = leftPadding; TopPadding = topPadding; RightPadding = rightPadding; BottomPadding = bottomPadding; Color = color; _sourcePatches = CreatePatches(textureRegion.Bounds); }
public Sprite(TextureRegion2D textureRegion) { if (textureRegion == null) throw new ArgumentNullException("textureRegion"); TextureRegion = textureRegion; Color = Color.White; IsVisible = true; Scale = Vector2.One; Effect = SpriteEffects.None; OriginNormalized = new Vector2(0.5f, 0.5f); }
public static void Draw( this SpriteBatch spriteBatch, TextureRegion2D textureRegion, RectangleF destinationRectangle, Color color, RectangleF?clippingRectangle = null) { if (textureRegion is NinePatchRegion2D ninePatchRegion) { Draw(spriteBatch, ninePatchRegion, destinationRectangle, color, clippingRectangle); } else { Draw(spriteBatch, textureRegion.Texture, textureRegion.Bounds, destinationRectangle, color, clippingRectangle); } }
public TextureRegion2D CreateRegion(string name, int x, int y, int width, int height) { if (_regionMap.ContainsKey(name)) { throw new InvalidOperationException("Region {0} already exists in the texture atlas"); } var region = new TextureRegion2D(Texture, x, y, width, height); _regionMap.Add(name, region); return(region); }
public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Rectangle destinationRectangle, Color color, Rectangle?clippingRectangle = null) { var ninePatchRegion = textureRegion as NinePatchRegion2D; if (ninePatchRegion != null) { Draw(spriteBatch, ninePatchRegion, destinationRectangle, color, clippingRectangle); } else { Draw(spriteBatch, textureRegion.Texture, textureRegion.Bounds, destinationRectangle, color, clippingRectangle); } }
public void TextureRegion2D_Specified_Test() { var graphicsDevice = TestHelper.CreateGraphicsDevice(); var texture = new Texture2D(graphicsDevice, 100, 200); var textureRegion = new TextureRegion2D(texture, 10, 20, 30, 40); Assert.AreSame(texture, textureRegion.Texture); Assert.AreEqual(10, textureRegion.X); Assert.AreEqual(20, textureRegion.Y); Assert.AreEqual(30, textureRegion.Width); Assert.AreEqual(40, textureRegion.Height); Assert.IsNull(textureRegion.Tag); }
private void RenderLayer(TiledMap map, TiledTile tile, TextureRegion2D region) { switch (map.Orientation) { case TiledMapOrientation.Orthogonal: RenderOrthogonal(tile,region); break; case TiledMapOrientation.Isometric: RenderIsometric(tile, region); break; case TiledMapOrientation.Staggered: throw new NotImplementedException("Staggered maps are currently not supported"); default: throw new ArgumentOutOfRangeException(); } }
private static Dictionary<char, BitmapFontRegion> BuildCharacterMap(Texture2D[] textures, BitmapFontFile fontFile) { var characterMap = new Dictionary<char, BitmapFontRegion>(); foreach (var fontChar in fontFile.Chars) { var pageIndex = fontChar.Page; var character = (char)fontChar.ID; var texture = textures[pageIndex]; var region = new TextureRegion2D(texture, fontChar.X, fontChar.Y, fontChar.Width, fontChar.Height); var fontRegion = new BitmapFontRegion(region, fontChar); characterMap.Add(character, fontRegion); } return characterMap; }
//protected override void Initialize() //{ // base.Initialize(); // _graphicsDeviceManager.IsFullScreen = true; // _graphicsDeviceManager.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width; // _graphicsDeviceManager.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height; // _graphicsDeviceManager.ApplyChanges(); //} protected override void LoadContent() { _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480); _guiManager = new GuiManager(_viewportAdapter, GraphicsDevice); _font = Content.Load<BitmapFont>("Fonts/courier-new-32"); var normal = new GuiTextureRegionDrawable(new TextureRegion2D(Content.Load<Texture2D>("Gui/button-normal"))); var pressed = new GuiTextureRegionDrawable(new TextureRegion2D(Content.Load<Texture2D>("Gui/button-clicked"))); var hover = new GuiTextureRegionDrawable(new TextureRegion2D(Content.Load<Texture2D>("Gui/button-hover"))); var buttonStyle = new GuiButtonStyle(normal, pressed, hover); var button = new GuiButton(buttonStyle) { Position = new Vector2(400, 240) }; button.Clicked += (sender, args) => { if (_player != null) { Explode(_player.Position, 3); _player.Destroy(); _player = null; } }; _guiManager.Controls.Add(button); var labelStyle = new GuiLabelStyle(_font); var label = new GuiLabel(labelStyle, "Hello") { Position = new Vector2(100, 100) }; label.MouseUp += (sender, args) => label.Text = args.Position.ToString(); _guiManager.Controls.Add(label); _camera = new Camera2D(_viewportAdapter); _explosionAnimations = Content.Load<SpriteSheetAnimationGroup>("explosion-animations"); _spriteBatch = new SpriteBatch(GraphicsDevice); _backgroundTexture = Content.Load<Texture2D>("black"); var bulletTexture = Content.Load<Texture2D>("laserBlue03"); var bulletRegion = new TextureRegion2D(bulletTexture); _bulletFactory = new BulletFactory(_entityManager, bulletRegion); SpawnPlayer(_bulletFactory); _meteorFactory = new MeteorFactory(_entityManager, Content); for (var i = 0; i < 13; i++) _meteorFactory.SpawnNewMeteor(_player.Position); }
private void SpawnPlayer(BulletFactory bulletFactory) { var spaceshipTexture = Content.Load<Texture2D>("playerShip1_blue"); var spaceshipRegion = new TextureRegion2D(spaceshipTexture); _player = _entityManager.AddEntity(new Spaceship(spaceshipRegion, bulletFactory)); }
public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Vector2 position, Color color, RectangleF?clippingRectangle = null) { Draw(spriteBatch, textureRegion, position, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0, clippingRectangle); }
public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Rectangle destinationRectangle, Color color) { spriteBatch.Draw(textureRegion.Texture, destinationRectangle, textureRegion.Bounds, color); }
public NinePatchRegion2D(TextureRegion2D textureRegion, int padding) : this(textureRegion, padding, padding, padding, padding) { }
public abstract void Draw(TextureRegion2D textureRegion, FRectangle destinationRectangle, Color color);
public NinePatchRegion2D(TextureRegion2D textureRegion, int leftPadding, int topPadding, int rightPadding, int bottomPadding) : this(textureRegion, new Thickness(leftPadding, topPadding, rightPadding, bottomPadding)) { }
public override void Draw(TextureRegion2D textureRegion, Vector2 position, Color color) { #if DEBUG IncRenderSpriteCount(); #endif internalBatch.Draw(textureRegion.Texture, position, textureRegion.Bounds, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0); }
public void Sprite_PreserveNormalizedOriginWhenTextureRegionChanges_Test() { var graphicsDevice = TestHelper.CreateGraphicsDevice(); var texture = Substitute.For<Texture2D>(graphicsDevice, 100, 100); var textureRegion = new TextureRegion2D(texture, 10, 20, 30, 40); var sprite = new Sprite(textureRegion); Assert.AreEqual(new Vector2(0.5f, 0.5f), sprite.OriginNormalized); Assert.AreEqual(new Vector2(15, 20), sprite.Origin); sprite.TextureRegion = new TextureRegion2D(texture, 30, 40, 50, 60); Assert.AreEqual(new Vector2(0.5f, 0.5f), sprite.OriginNormalized); Assert.AreEqual(new Vector2(25, 30), sprite.Origin); }
private static void LoadContent(ContentManager content) { AtlasTextures = content.Load<TextureAtlas>(TEXTURE_ASSETNAME); TexTileBorder = AtlasTextures["grid"]; TexCannonBody = AtlasTextures["simple_circle"]; TexCannonBodyShadow = AtlasTextures["cannonbody_shadow"]; TexCannonBarrel = AtlasTextures["cannonbarrel"]; TexCannonBarrelShadow = AtlasTextures["cannonbarrel_shadow"]; TexCannonCrosshair = AtlasTextures["cannoncrosshair"]; TexLevelNodeStructure = AtlasTextures["levelnode_structure"]; TexLevelNodeSegment = AtlasTextures["levelnode_segment"]; AnimCannonCog = Enumerable.Range(0, ANIMATION_CANNONCOG_SIZE).Select(p => AtlasTextures[$"cannoncog_{p:000}"]).ToArray(); TexBullet = AtlasTextures["cannonball"]; TexBulletSplitter = AtlasTextures["cannonball_piece"]; TexCircle = AtlasTextures["simple_circle"]; TexCircleEmpty = AtlasTextures["simple_circle_empty"]; TexPixel = AtlasTextures["simple_pixel"]; TexPixel = new TextureRegion2D(TexPixel.Texture, TexPixel.X + TexPixel.Width / 2, TexPixel.Y + TexPixel.Height / 2, 1, 1); // Anti-Antialising TexParticle = Enumerable.Range(0, 16).Select(p => AtlasTextures[$"particle_{p:00}"]).ToArray(); TexHUDButtonBase = AtlasTextures["hud_button_base"]; TexHUDButtonPause = Enumerable.Range(0, ANIMATION_HUDBUTTONPAUSE_SIZE).Select(p => AtlasTextures[$"hud_pause_{p:00}"]).ToArray(); TexHUDButtonSpeedHand = AtlasTextures["hud_time_hand"]; TexHUDButtonSpeedSet0 = AtlasTextures["hud_time_0"]; TexHUDButtonSpeedSet1 = AtlasTextures["hud_time_1"]; TexHUDButtonSpeedSet2 = AtlasTextures["hud_time_2"]; TexHUDButtonSpeedSet3 = AtlasTextures["hud_time_3"]; TexHUDButtonSpeedSet4 = AtlasTextures["hud_time_4"]; TexHUDButtonSpeedClock = AtlasTextures["hud_time_clock"]; TexHUDButtonPauseMenuMarker = AtlasTextures["pausemenu_marker"]; TexHUDButtonPauseMenuMarkerBackground = AtlasTextures["pausemenu_marker_background"]; TexPanelBlurEdge = AtlasTextures["panel_blur_edge"]; TexPanelBlurCorner = AtlasTextures["panel_blur_corner"]; TexPanelCorner = AtlasTextures["panel_corner"]; TexIconBack = AtlasTextures["icon_back"]; TexIconNext = AtlasTextures["icon_next"]; TexIconRedo = AtlasTextures["icon_redo"]; TexDifficulty0 = AtlasTextures["difficulty_0"]; TexDifficulty1 = AtlasTextures["difficulty_1"]; TexDifficulty2 = AtlasTextures["difficulty_2"]; TexDifficulty3 = AtlasTextures["difficulty_3"]; HUDFontRegular = content.Load<SpriteFont>("fonts/hudFontRegular"); HUDFontBold = content.Load<SpriteFont>("fonts/hudFontBold"); #if DEBUG DebugFont = content.Load<SpriteFont>("fonts/debugFont"); DebugFontSmall = content.Load<SpriteFont>("fonts/debugFontSmall"); #endif StaticTextures.DEFAULT_TEXTURE_SCALE = DEFAULT_TEXTURE_SCALE; StaticTextures.SinglePixel = TexPixel; StaticTextures.PanelBlurCorner = TexPanelBlurCorner; StaticTextures.PanelBlurEdge = TexPanelBlurEdge; StaticTextures.PanelCorner = TexPanelCorner; }
public override void Draw(TextureRegion2D textureRegion, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { #if DEBUG IncRenderSpriteCount(); #endif internalBatch.Draw(textureRegion.Texture, position, textureRegion.Bounds, color, rotation, origin, scale, effects, layerDepth); }
public abstract void Draw(TextureRegion2D textureRegion, Vector2 position, Color color);
public abstract void Draw(TextureRegion2D textureRegion, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth);
private void RenderIsometric(TiledTile tile, TextureRegion2D region) { var tx = (tile.X*(_map.TileWidth / 2)) - (tile.Y*(_map.TileWidth / 2)) //Center + (_map.Width * (_map.TileWidth/2)) //Compensate Bug? - (_map.TileWidth / 2); var ty = (tile.Y*(_map.TileHeight/2)) + (tile.X*(_map.TileHeight/2)) //Compensate Bug? - (_map.TileWidth + _map.TileHeight); _spriteBatch.Draw(region, new Rectangle(tx, ty, region.Width, region.Height), Color.White); }
public NinePatchRegion2D(TextureRegion2D textureRegion, Thickness padding) : base(textureRegion.Name, textureRegion.Texture, textureRegion.X, textureRegion.Y, textureRegion.Width, textureRegion.Height) { Padding = padding; SourcePatches = CreatePatches(textureRegion.Bounds); }
private void DrawPolygonEdge(TextureRegion2D texture, Vector2 point1, Vector2 point2, Color color, float thickness) { #if DEBUG IncRenderSpriteCount(); #endif var length = Vector2.Distance(point1, point2); var angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X); var scale = new Vector2(length, thickness); internalBatch.Draw( texture: texture.Texture, position: point1, sourceRectangle: texture.Bounds, color: color, rotation: angle, scale: scale); }
public NinePatchRegion2D(TextureRegion2D textureRegion, int leftRightPadding, int topBottomPadding) : this(textureRegion, leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding) { }
public override void Draw(TextureRegion2D textureRegion, FRectangle destinationRectangle, Color color) { #if DEBUG IncRenderSpriteCount(); #endif internalBatch.Draw(textureRegion.Texture, destinationRectangle.Truncate(), textureRegion.Bounds, color); }
public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Vector2 position, Color color) { var sourceRectangle = textureRegion.Bounds; spriteBatch.Draw(textureRegion.Texture, position, sourceRectangle, color); }
public BulletFactory(IEntityManager entityManager, TextureRegion2D bulletRegion) { _entityManager = entityManager; _bulletRegion = bulletRegion; }