我一直致力于角色动作,我创造了一种方法,当按下向上键时使角色跳跃,但角色的动作没有反应。
任何人都可以看到有什么问题?这是我的代码:
构造
public PlayerSprite(string name, string magicTextureName,Vector2 position, Vector2 velocity, AnimatedTextureData textureData, SpritePresentationInfo spritePresentationInfo,SpritePositionInfo spritePositionInfo, Keys leftKey, Keys rightKey, int frameRate, int startFrame, bool bRepeatAnimation)
: base(name, textureData, spritePresentationInfo, spritePositionInfo, frameRate, startFrame, bRepeatAnimation)
占据位置和速度。
这是在更新中。
if (SpriteManager.GAME.KEYBOARDMANAGER.isFirstKeyPress(Keys.Up))
{
bPause = false;
updateJump();
}
updateJump函数
public void updateJump()
{
jumpPosition += jumpVelocity;
if (Keyboard.GetState().IsKeyDown(Keys.Right))
jumpVelocity.X = 3f;
else if (Keyboard.GetState().IsKeyDown(Keys.Left))
jumpVelocity.X = -3f;
else
jumpVelocity.X = 0f;
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
jumpPosition.Y -= 10f;
jumpVelocity.Y -= 5f;
hasJumped = true;
}
if (hasJumped == true)
{
float i = 1;
jumpVelocity.Y += 0.15f * i;
}
if (jumpPosition.Y + animatedTextureData.Height() >= 450)
{
hasJumped = false;
}
if (hasJumped == false)
{
jumpVelocity.Y = 0f;
}
}
我在主要的地方称呼这个
AnimatedTextureData playerAnimatedTextureData = (AnimatedTextureData)textureManager.Get("PlayerAnimation");
SpritePresentationInfo playerAnimatedPresentationInfo = new SpritePresentationInfo(playerAnimatedTextureData.FULLSOURCERECTANGLE, 1);
SpritePositionInfo playerAnimatedPositionInfo = new SpritePositionInfo(new Vector2(100, 700), playerAnimatedTextureData.Width(), playerAnimatedTextureData.Height(), 0, 2, playerAnimatedTextureData.CENTREORIGIN);
this.playerSprite = new PlayerSprite("PlayerAnimation", "FireballAnimation", new Vector2(50, 50), new Vector2(50, 50), playerAnimatedTextureData, playerAnimatedPresentationInfo, playerAnimatedPositionInfo,Keys.Left, Keys.Right, 10, 0, true);
spriteManager.Add(playerSprite);
答案 0 :(得分:3)
我的猜测: 我不知道这个函数是做什么编程的,但是如果它只检测到按下向上键,那么在第一帧之后不再更新跳转。
if (SpriteManager.GAME.KEYBOARDMANAGER.isFirstKeyPress(Keys.Up))
{
bPause = false;
updateJump();
}
一旦你纠正了这个并且每个更新周期调用了updateJump()函数,只要你按住向上键,火球就会很快逃离屏幕。