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

Sprite sticks to the camera in libgdx?

I would like to let the sprite where I left it in the screen, and drag the camera in the world. But the sprite sticks to the camera, and is still at the bottom of the screen when I drag the camera. This is not happening with a tilemap (the .tmx…
Paul
  • 6,108
  • 14
  • 72
  • 128
0
votes
1 answer

XNA - drawing many rectangles causes lag

I am creating a game in XNA that will require thousands of tiny rectangles / squares to be drawn. As the number increases, the performance gets worse. Here is the code I am current using: protected override void Draw(GameTime gameTime) { …
0
votes
1 answer

Matrix Create scale, what is happening here?

I'm trying to perform some matrix transformations with the spritebatch and I don't understand what is happening with the scale matrix. rotM = Matrix.CreateTranslation(0, 0, 0) *…
0
votes
1 answer

XNA 4.0 Use Multiple Effects In One Batch

I'm working on a graphics engine for XNA 4.0, and I've encountered a problem that I can't find any solution for. Currently I'm trying to implement light-effects by using shaders. The graphics engine also consists of an particle engine and therefore…
0
votes
1 answer

Does using a static Texture2D with SpriteBatch improve performance?

I am going to have lots of (same looking) zombies in my game. Is it a good idea to make the texture static, so that SpriteBatch wont need to load a new texture? I go through the whole zombie list and draw every zombie with the same call, just…
0
votes
1 answer

Sprite Batching: advanced technique

I'm making OpenGL2 based application, which renders over 200 sprites in each iteration. I would like to use less drawcalls, since often I render multiple sprites with same texture. Unfortunately, regular batching technique is not good for me because…
JacksonRR
  • 227
  • 1
  • 3
  • 12
0
votes
1 answer

Wobbling texture using source rectangle

I'm having a little trouble with a texture2d I'm trying to draw in XNA. Basically, I have a power-up "cooldown fill-effect" going on. I have a texture that I'm trying to draw partially as the cooldown decreases. So, for example, at 10% cooldown done…
Timeaisis
  • 3
  • 1
0
votes
1 answer

Scaling an image with LibGDX SpriteBatches

I have my image (for the sake of explaining, lets call it Image.png) and I'm trying to get it to scale to properly fit in my Bodies I have drawn. The bodies and everything work with the debug but I'm not a fan of it.. I'm using a SpriteBatch to draw…
Chris
  • 2,435
  • 6
  • 26
  • 49
0
votes
1 answer

SpriteBatch.Draw in rectangle

I want to make something like Terraria item sidebar thing. (the Left-top rectangles one). And here is my code. Variables are public Rectangle InventorySlots; public Item[] Quickbar = new Item[9]; public Item mouseItem = null; public…
0
votes
1 answer

XNA 4.0 SetRenderTarget result in full purple screen

I'm currently making a 2D side-scroller game with XNA for my personal project. My goal for the moment is to have fun with shaders. But I'm actually stuck by the SetRenderTarget(RenderTarget2D) method, I don't understand why once i call it the game…
RationalGaze
  • 56
  • 1
  • 10
0
votes
1 answer

Billboard Transparency in XNA for Windows Phone

Okay so hopefully a simple fix that I'm just not seeing: I'm trying to implement transparency on a Billboard for an explosion, however the sprite stays solid where there is a pixel not defined transparent in the png file itself. I'm trying to change…
TotalJargon
  • 147
  • 2
  • 2
  • 14
0
votes
1 answer

XNA: Polygon Source from Texture2D

I've got a problem. Using SpriteBatch, I can only draw a rectangle area from my source Texture2D. Please, help me to find the way, how I can draw polygon or circle area from my source texture. I'm creating 2d sprite game. Thanks in advance, Denis
0
votes
1 answer

XNA 4.0: terrain glitches caused by SpriteBatch

I'm trying to implement terrain collision in XNA so I've added some dynamic text that allows me to test whether calculations are correct. Everything was rendered just fine until I called: spriteBatch.Begin();…
thormond
  • 27
  • 5
0
votes
1 answer

Xna spriteBatch in different class

I'm about ready to tear my hair out because spriteBatch() is just not "clicking" with me. I can't seem to find anything online that covers my use of this in this exact situation, which makes me believe I'm missing something incredibly simple. I've…
Eric
  • 2,201
  • 5
  • 29
  • 35
0
votes
1 answer

Jerky sprite (2d) movement with OpenGL ES 2.0 on Android

Edit 2. Added screenshot of logcat. If I reduce the number of sprites to 1, I still get this intermittent 'stop/starting' - so I don't think it's my code, as with 1 sprite my frame rate hovers around 85-90 fps. I'm guessing it's something on the…
Zippy
  • 3,826
  • 5
  • 43
  • 96