Reputation: 454
In below code I am using two textures for player. is its normal animation and another for its jumping animation. While running with following code at the time jumping only few of frames are running not all.
public void draw(Object sender,GameTimerEventArgs e)
{
jumpframe++;
if (jumpframe > 32)
{
jumpframe = 0;
}
TouchPanel.EnabledGestures = GestureType.Tap;
TouchCollection touches = TouchPanel.GetState();
if ( touches.Count >0)
{
touch = true;
jump();
System.Diagnostics.Debug.WriteLine("touch");
}
else if (touches.Count == 0)
{
playerr();
System.Diagnostics.Debug.WriteLine(currentframe);
touch = false;
}
spriteBatch.Draw(Texture.player[currentframe], Texture.position, Color.White);
spriteBatch.Draw(Texture.jumpplayer[jumpframe], Texture.jumpposition, Color.White);
currentframe++;
if (currentframe > 24)
{
currentframe = 0;
}
System.Diagnostics.Debug.WriteLine(jumpframe);
spriteBatch.End();
// TODO: Add your drawing code here
}
public void jump()
{
Texture.jumpposition.X = 10;
Texture.jumpposition.Y = 243;
Texture.position.X = -200;
Texture.position.Y = 243;
}
public void playerr()
{
Texture.position.X = 10;
Texture.position.Y = 243;
Texture.jumpposition.X = -400;
Texture.jumpposition.Y = 243;
}
}
Upvotes: 0
Views: 122
Reputation: 4213
If jumpframe
is incremented and Texture.jumpplayer[jumpframe]
is scanned correctly I think your problem is in Texture.jumpposition
definition.
Just a suggestion: detect touches in your Update
method, not in the Draw
, that method should only be used for drawing instructions.
Upvotes: 1