0

好的,所以我在写像泡泡一样的 2d 游戏,但我不想要某种非常复杂的动画。我想要这样的东西:我有 2 个玩家图像右面生物和左面生物图像的矩形大小完全相同,我也有:

Vector2 playerPosition宣布

player = Content.Load<Texture2D>("PlayerRight");在我的LoadContent

spriteBatch.Draw(player, playerPosition, Color.White);在我的绘图功能中

我想要的只是当我按下右/左箭头按钮时,我的播放器图像在右/左图像之间切换

我不知道什么样的代码以及我必须为该任务编写的位置。如果您需要有关该任务的更多信息,请告诉我

4

1 回答 1

0

this is not best solution, but it could give you hint.

playerRight = Content.Load<Texture2D>("PlayerRight");
playerLeft = Content.Load<Texture2D>("PlayerLeft");
playerCameraFacing = Content.Load<Texture2D>("playerCameraFacing");

declare PlayerSprite as Texture2D in player class

update funciton pseudo:

PlayerSprite = playerCameraFacing ;
if key.left then PlayerSprite = playerLeft;
if key.right then PlayerSprite = playerRight;

draw function pseudo:

draw(PlayerSprite, Position, Color)

i put all my animation frames into single image, and then show them using "sourceRectangle". what is source rectangle in spritebatch.draw in xna http://msdn.microsoft.com/en-us/library/ff433988.aspx

于 2013-03-23T07:53:12.153 回答