开发者

How to place sprites at specific x,y coordinates in xna 4.0

开发者 https://www.devze.com 2023-03-21 05:56 出处:网络
Okay im working on making a tic tac toe game for one of my game development courses using XNA 4.0 I need to place sprites or some other objects so the game can check if the mouse is being clicked in t

Okay im working on making a tic tac toe game for one of my game development courses using XNA 4.0 I need to place sprites or some other objects so the game can check if the mouse is being clicked in the correct spots. I am going to use transparent sprites as a kind of button. How do I code them to go to these specific x,y co开发者_C百科ordinates. The game board is drawn on the background, I have all the coordinates to where to place these sprites. I am just stuck on putting the sprites in the correct positions.


SpriteBatch.Draw has a position parameter. Pass in an appropriately-valued Vector2.


Well if you check the Draw method you will find a parameter for the position. Check this code sample

spriteBatch.Begin();
Vector2 pos = new Vector2(10, 10);
spriteBatch.Draw(SpriteTexture, pos, Color.White);
spriteBatch.End();

This is how you draw a sprite, with SpriteTexture as the image, on the position x10, y10 with the color White to modulate the texture.

You can also find more informations here.


Keep in mind that there are many overloaded methods to the Draw method. One you can even pass in rotation information and the like. So .Draw(...) has a lot of functionality you can use beyond just placing a sprite.

0

精彩评论

暂无评论...
验证码 换一张
取 消