Questions tagged [spritebatch]

Used in the XNA Framework. Enables a group of sprites to be drawn using the same settings.

SpriteBatch is a commonly used object for drawing 2D bitmaps in XNA. It allows developers to draw a sprite in their XNA Application, with a variety of options. It is included in Microsoft.Xna.Framework.Graphics

To start, you must initialize a SpriteBatch:

SpriteBatch batch1 = new SpriteBatch();

Now you can use batch1. To begin the SpriteBatch, call SpriteBatch.Begin() in your Draw method. Advanced users can add arguments as seen here.

Then you can draw a sprite with with the Draw(..) method.

SpriteBatch.Draw(Texture2D, Rectangle, Color);

That is the simplest of the SpriteBatch.Draw method, you can use other arguments such as Vector2 for position, and SpriteEffects. You can also draw text using SpriteFonts and the appropriate overload: SpriteBatch.DrawString (SpriteFont, String, Vector2, Color)

To end the SpriteBatch simply call SpriteBatch.End();

For more information, see the MSDN documentation for SpriteBatch.

184 questions
0
votes
1 answer

Libgdx: Textures drawn in Actor too big

I'm trying to draw a texture. This works well as long as I do this in my Screen's render method: public void render(float delta) { batch.begin(); batch.draw(new Texture(Gdx.files.internal("badlogic.jpg")), 0f, 0f, 100, 100f); …
SpoKaPh
  • 167
  • 2
  • 12
0
votes
1 answer

Drawing custom sprites onto a button in monogame

I'm using monogame. I want to overlay Text onto one of my button images, but I want to use the image way of drawing; spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White); so that I can control how the text is handled inside…
0
votes
1 answer

How to create an ImageButton with multiple Sprite/Texture layers in LibGDX?

I'm designing a game that requires generating a vast array of buttons, with different combinations of background colors and outlines. I already have a Sprite for the background and a Sprite for the outline and apply tints to each. I've already…
Miguel Mano
  • 103
  • 1
  • 12
0
votes
0 answers

Drawing Sprites although Origin is offscreen Libgdx

I´m developing my first game in Libgdx. I have a Orthographic camera which follow a ball jumping like "Flappy Bird". My spinning obstacles have the origin in the middle because they are "attached" to some box2d bodies. My problem is that…
k0k0ss
  • 1
  • 1
0
votes
1 answer

C++ DirectXTK Changing SpriteTint Over Time

So for a University Project I am looking to try and change the tint of a sprite over a specific time frame. The aim is to make a set of rocks turn from grey to orange (simulating heating them up) over 5 seconds, then turn them from orange to grey…
0
votes
1 answer

Spritebatch drawing in wrong position

Why is my sprite drawing to the top left corner when my wizardPos variable clearly puts it at the middle of the screen? //in load content wizardPos = new Vector2(graphics.PreferredBackBufferWidth /2, 700); wizardChar = new Characters.Wizard(this,…
D_Wagner
  • 87
  • 1
  • 1
  • 9
0
votes
1 answer

Restarting a SpriteBatch with the same parameters it started with

Is it possible to receive a passed in SpriteBatch that already has had Begin() called, call End() on it because you want to change the RenderTarget, then call Begin() on it again with the same parameters that were passed in initially?
GameKyuubi
  • 681
  • 1
  • 10
  • 25
0
votes
1 answer

SpriteBatch draws to backbuffer instead of RenderTarget?

Here's a draw block: graphicsDevice.Clear(Color.CornFlowerBlue); spriteBatch.Begin(); graphicsDevice.SetRenderTarget(renderTarget); spriteBatch.Draw(texture2D, position,…
GameKyuubi
  • 681
  • 1
  • 10
  • 25
0
votes
0 answers

libGdx: My actor's sprite is rendedred like a black box on stage

I'm a rudiment in libGdx. I'm developing a turn-based strategy game in Android. Yesterday, I created an Archer who can shoot to distant units. I succeeded in showing kinda archery motion when the gamer decided to do it by using Animaion, but It is…
0
votes
1 answer

libGDX: How to disable the color on SpriteBatch?

With some assets, I'm trying to implement is so that I have a grayscale image, and use the Batch#setColor method to paint over it programmatically. However, can Batch#setColor be disabled afterwards for rendering of the rest of the assets? I only…
Seth Falco
  • 313
  • 6
  • 22
0
votes
1 answer

The text drawn using "batch" is hidden by a rectangle drawed using "renderer"

I've just begun using LibGDX and I'm encountering a problem using batch: I have a render method in my HomeScreen that renders pretty much everything on the screen, including some Buttons. In my class Button, I render the buttons and afterwards, I…
Vellyxenya
  • 79
  • 8
0
votes
1 answer

Libgdx SpriteBatch draws Actors, but not other Textures

It's been a while since I used LibGdx, so I feel like I'm just missing something obvious. My render method in MyGdxGame looks like this, calling for the stage to draw itself (along with its actors), and then I try to draw a set of textures for…
DoubleDouble
  • 1,493
  • 10
  • 25
0
votes
1 answer

MonoGame Different Size RenderTargets and Scaling issues

I've got some different controls I have that I'm drawing to different size render targets. If I draw a 64x64 textureA to an 800x600 render target like this. Graphics.SetRenderTarget(Canvas); _spriteBatch.Draw(textureA, new Rectangle(0, 0, 64, 64),…
Kyle Gobel
  • 5,530
  • 9
  • 45
  • 68
0
votes
1 answer

Drawing score on LibGDX/Java

I make a catching to drops game but I should draw the users score on top left side of the screen. I use this code: private SpriteBatch sayfa; sayfa.begin(); scoreboard.draw(sayfa, score, 10,10); sayfa.end(); But they aren't work because of you can…
user5280387
0
votes
1 answer

Libgdx, sprite batch and setColor to specific region

So I have a simple texture: one big green circle in the center and one small white circle also in the center of my texture. And now I want to change color of my white circle to yellow in my app. Is it possible and what is the best way to set color…
Dragomirus
  • 439
  • 3
  • 14