캐릭터를 움직이게하고 왼쪽이나 오른쪽으로 걸어 가려고합니다. 기본적인 애니메이션을 만드는 방법을 배웠지 만, 그 사이를 전환하는 방법을 알 수는 없습니다.C# XNA 프로그램에서 애니메이션을 어떻게 전환합니까?
왼쪽으로 걸어 가면 '유휴'(animatedSprite) 애니메이션에서 'walking left'(animatedSprite2) 애니메이션으로 전환하고 싶습니다.
당신이 그렇게 명확하게 문제의 표현처럼using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace WalkingAnimation
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private AnimatedSprite animatedSprite, animatedSprite2;
private Vector2 position = new Vector2(350f, 200f);
private KeyboardState keyState;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
Texture2D texture = Content.Load<Texture2D>("Idle");
Texture2D texture2 = Content.Load<Texture2D>("Run");
animatedSprite = new AnimatedSprite(texture, 1, 11);
animatedSprite2 = new AnimatedSprite(texture2, 1, 10);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.Q))
{
position.X -= 3;
}
if (keyState.IsKeyDown(Keys.P))
{
position.X += 3;
}
base.Update(gameTime);
animatedSprite.Update();
animatedSprite2.Update();
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
animatedSprite.Draw(spriteBatch, position);
}
}
}
이것은 효과가 있습니다. 고맙습니다. :) – Kashin