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
1
vote
1 answer

SpriteBatch set below the level of the Actor in libgdx

I'm making a game in libgdx , and I've added different Actor forming my scene . Currently however, I added a texture: //other variables: Texture texture; int sourceX = 0; //create() method texture = new…
Mr. Developer
  • 3,295
  • 7
  • 43
  • 110
1
vote
3 answers

Windows script doesn't work when user types in a whitespace

I'm writing a Windows script in batch. I have a problem with whitespaces in variables. When the user types in a space, the script breaks. Here's the part of my script: :package SET /P packageName="Set package name:" IF [%packageName%] EQU [] ( …
Monika
  • 179
  • 1
  • 1
  • 9
1
vote
1 answer

Why does implementing text have adverse impact on 3D models in Visual Studio XNA?

When I tried adding text to my MonoGame program, I encountered a problem. It stopped rendering 3D objects properly, cutting front faces on some, not displaying others altogether. I've tried ending the batch after drawing the models too, to the same…
Corpserule
  • 13
  • 5
1
vote
3 answers

LibGDX SpriteBatch rendering error

So earlier when I was testing my game everything went well, then I added some code. In my game I have states like PlayState or MenuState and now everything goes well, but when I try to switch the states in-game, the following error occurs: Exception…
user4441930
1
vote
1 answer

Monogame sprite alpha blending

At the moment, I am having a 2D grid of terrain textures, which I am drawing using the standard XNA/Monogame spritebatch.Draw() function. In order to have smoother transitions between adjacent but different terrain textures, I would like to blend…
mgulde
  • 215
  • 3
  • 10
1
vote
1 answer

Libgdx - Colouring only part of a sprite dynamically

Have an Android application running Libgdx with many sprites all floating around. Currently I colour them all differently depending on which group they belong to, eg "red", "green", "blue" etc. However, I think I'd prefer to only colour part of the…
Jammo
  • 1,838
  • 4
  • 25
  • 39
1
vote
2 answers

Why doesn't SpriteBatch draw anything (LibGdx)?

This is from day 6 of the flappy bird recreation tutorial -http://www.kilobolt.com/day-6-adding-graphics---welcome-to-the-necropolis.html Here is the image file i am using for texture in my game. It is a 256px x 64px .png file. Here is the class…
committedandroider
  • 8,711
  • 14
  • 71
  • 126
1
vote
1 answer

Libgdx - Rotated body looks pixelated

I have this problem that is driving me nuts! So, when I draw a boxshape body with an angle different to zero on SpriteBatch(and even on Box2DDebugRenderer happens the same), the body looks pixelated in my computer's screen. This problem persists…
blaswtf
  • 91
  • 1
  • 6
1
vote
0 answers

LibGDX: Disable transparency in SpriteBatch/Sprite

I need to disable transparency in a Sprite or SpriteBatch. I can't find any methods to do that for a Sprite, and when I call .DisableBlending() on a SpriteBatch, and then I call .EnableBlending(), but doesn't get enabled again until it ends. Code…
Anuken
  • 65
  • 11
1
vote
0 answers

LibGDX - Efficient way to use tiles & Z-Order of Sprites

I have a problem. The sprites I'm rendering aren't in the Z position I want them to be. The game I'm making is a 2D sandbox game - similar to terraria. I make a 2-dimensional array and then iterate through it with a for-loop. Basic code…
Anuken
  • 65
  • 11
1
vote
2 answers

In libgdx's Batch interface, what are these arguments used for?

I'm trying to figure out what all these arguments do, as when I draw my bullet image it appears as a solid block instead of a sprite that alternates between solid color and an empty portion (i.e instead of 10101 it's 11111, with 0's being empty…
ramboCODER
  • 73
  • 9
1
vote
2 answers

XNA 4.0: How to remove text after drawn to screen?

Good day everyone. I'm trying to draw the text "Pass Complete!" to screen with this code: spriteBatch.DrawString(font, "PASS COMPLETE!", new Vector2(30, 130), Color.White); Which does fire off the proper IF statement. However, how do I go about then…
AriesTiger
  • 69
  • 1
  • 8
1
vote
1 answer

Performance cost of rendering tile in LibGDX

I am programming tile based strategy game, so I have orthographic view. The rendered screen has 40*20 tiles wide and each tile has got 50*50px texture. I have one layer of tiles (let's say grass) and I place walls on top of it. The game runs…
Vilda
  • 1,675
  • 1
  • 20
  • 50
1
vote
1 answer

DirectX SpriteBatch.Draw: What is layer depth?

The definition on MSDN website is: layerDepth Type: Single The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing. Can someone explain what…
sitBy
  • 271
  • 5
  • 19
1
vote
1 answer

libGDX - Delete/Subtract regions of a texture from SpriteBatch?

I have a number of square regions in my game screen which, when actors move across these regions, I want the background image to show through from behind. So, is it possible to draw to a SpriteBatch such that a region is subtracted/deleted from the…
Bumpy
  • 1,290
  • 1
  • 22
  • 32