0
내가 얻으려고하는 것은 문자가 정적 프레임에있는 현실적인 도보 애니메이션이고 오른쪽을 누르면 생성 된 캐릭터 애니메이션이로드됩니다.다른 키를 눌렀을 때 스프라이트 시트에서 프레임을 변경하는 방법. XNA
나는 이것으로 주변을 어슬렁 거리며 시도했다. 그리고 지금까지 내가 얻었던 모든 것은 오류 다.
스프라이트
public class Sprite
{
public static SpriteManager spriteManager;
private int sectorNumber;
private string name;
private TextureData textureData;
private SpritePresentationInfo spritePresentationInfo;
private SpritePositionInfo spritePositionInfo;
public Sprite(string name, TextureData textureData,
SpritePresentationInfo spritePresentationInfo,
SpritePositionInfo spritePositionInfo)
{
this.name = name;
this.textureData = textureData;
this.spritePresentationInfo = spritePresentationInfo;
this.spritePositionInfo = spritePositionInfo;
//make sure we set first time around
this.sectorNumber = Collision.getSectorNumber(this.POSITIONINFO.BOUNDS);
}
AnimatedSprite
public class AnimatedSprite : Sprite
{
protected AnimatedTextureData animatedTextureData;
protected int frameRate, startFrame, currentFrame = 0;
protected bool bRepeatAnimation, bPause;
protected double timeSinceLastFrameInMs, timeBetweenFrameInMs;
#region PROPERTIES
#endregion
public AnimatedSprite(string name, AnimatedTextureData animatedTextureData,
SpritePresentationInfo spritePresentationInfo,
SpritePositionInfo spritePositionInfo,
int frameRate, int startFrame, bool bRepeatAnimation)
: base(name, animatedTextureData, spritePresentationInfo, spritePositionInfo)
{
this.animatedTextureData = animatedTextureData;// (AnimatedTextureData)animatedTextureData.Clone();
this.frameRate = frameRate;
timeBetweenFrameInMs = 1000.0/frameRate; //time between each frame if they play at frameRate per second (e.g. 24fps gives timeBetweenFrameInMs = 1000ms/24 per second)
timeSinceLastFrameInMs = timeBetweenFrameInMs; //means no initial delay in animation
this.startFrame = startFrame;
currentFrame = startFrame;
this.bRepeatAnimation = bRepeatAnimation;
}
PlayerSprite :
다음은 내 코드입니다.
public class PlayerSprite : Sprite
{
protected Keys leftKey, rightKey;
//private float moveIncrement = 0.5f;
private int move;
public PlayerSprite(string name, AnimatedTextureData textureData, SpritePresentationInfo spritePresentationInfo,
SpritePositionInfo spritePositionInfo, Keys leftKey, Keys rightKey)
: base(name, textureData, spritePresentationInfo, spritePositionInfo)
{
this.leftKey = leftKey;
this.rightKey = rightKey;
}
//-----------------------------------------------------------------------------------
// Use this if we do not want to use the parents
//-----------------------------------------------------------------------------------
public override void Update(GameTime gameTime)
{
handleInput(gameTime);
base.Update(gameTime);
}
//-----------------------------------------------------------------------------------
// Use this if we do not want to use the parents
//-----------------------------------------------------------------------------------
protected override void handleInput(GameTime gameTime)
{
this.move = (int)(GameData.PLAYER_MOVE_INCREMENT * gameTime.ElapsedGameTime.Milliseconds);
if (SpriteManager.GAME.KEYBOARDMANAGER.isKeyDown(leftKey))
MoveBy(-move, 0);
//This is where i want to initialize the walk animation.
if (SpriteManager.GAME.KEYBOARDMANAGER.isKeyDown(rightKey))
MoveBy(move, 0);
}
메인. 나는 메인에서 중요한 언론없이 일하고 움직이는 것을 가지고있다.
textureManager.Add("PlayerAnimation", "Assets\\Animations\\Characters\\Player\\Player_AnimationFinal", 8, 75,200);
//------------------------------------------------------------------------------------------------
//Player Animation
//------------------------------------------------------------------------------------------------
AnimatedTextureData playerAnimatedTextureData = (AnimatedTextureData)textureManager.Get("PlayerAnimation");
SpritePresentationInfo playerAnimatedPresentationInfo = new SpritePresentationInfo(playerAnimatedTextureData.FULLSOURCERECTANGLE, 0);
SpritePositionInfo playerAnimatedPositionInfo = new SpritePositionInfo(new Vector2(100, 700), playerAnimatedTextureData.Width(), playerAnimatedTextureData.Height(), 0, 2, playerAnimatedTextureData.CENTREORIGIN);
spriteManager.Add(new AnimatedSprite("PlayerAnimation", playerAnimatedTextureData, playerAnimatedPresentationInfo, playerAnimatedPositionInfo,10, 0, true));
//------------------------------------------------------------------------------------------------
아무도, 그 전부를 읽어 특정 문제에 질문을 좁힐려고하지 않습니다이
예와 같이
와 그립니다. – Cyral