2013-03-06 111 views
0

好吧,即时编写像泡泡跳的2D游戏我有精灵我已经做了物理(移动,跳跃,下降到目前为止:D)我做了某种拍摄,但现在我想让我的球员精灵(矩形图像)动画,但我不想要一些非常复杂的动画。我想是这样的:我有2个选手图像权面临的生物和左派面临的生物图像的矩形大小是完全一样的,我也有:XNA游戏工作室简单精灵动画

Vector2 playerPositionLoadContent

宣布

player = Content.Load<Texture2D>("PlayerRight");

spriteBatch.Draw(player, playerPosition, Color.White);我绘制函数

我要的是当我按下左/右 - 左/右脸图像

之间的箭头按钮,我的球员形象开关

我不知道什么样的代码和我必须写的任务。 如果您需要更多关于该任务的信息,请让我知道

回答

0

这不是最好的解决方案,但它可以给你提示。

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

声明PlayerSprite作为的Texture2D播放器类

更新功能可按伪:

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

绘制函数伪:

draw(PlayerSprite, Position, Color) 

我把我所有的动画帧到单个图像,然后使用“sourceRectangle”显示它们。 what is source rectangle in spritebatch.draw in xna http://msdn.microsoft.com/en-us/library/ff433988.aspx