캐릭터에 애니메이션을 적용하고 왼쪽과 오른쪽으로 걷게 만들려고합니다. 기본 애니메이션을 만드는 방법을 배웠지 만 전환 방법을 알 수 없습니다.
캐릭터가 왼쪽으로 걸을 때 나는 그가 '유휴'(animatedSprite) 애니메이션에서 '왼쪽으로 걷기'(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);
}
}
}
질문에서 명확하게 표현한 것처럼 Boolean
캐릭터가 유휴 상태인지 여부를 설명하는 저장 만하면됩니다.
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;
private bool idle;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
// Start of as idle
idle = true;
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
// Textures
Texture2D texture = Content.Load<Texture2D>("Idle");
Texture2D texture2 = Content.Load<Texture2D>("Run");
// Animations
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();
idle = true; // If the character doesn't move this will stay true
if (keyState.IsKeyDown(Keys.Q))
{
position.X -= 3;
idle = false;
}
if (keyState.IsKeyDown(Keys.P))
{
position.X += 3;
idle = false;
}
base.Update(gameTime);
animatedSprite.Update();
animatedSprite2.Update();
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
if(idle)
animatedSprite.Draw(spriteBatch, position);
else
animatedSprite2.Draw(spriteBatch, position);
}
}
}
그리고 그것은 당신이 원하는 것을해야합니다.
또한 애니메이션이 약간 어색해지면 스프라이트 시트를 사용하고 모든 플레이어 변수를 저장할 수있는 애니메이션 클래스를 만드는 것이 좋습니다. 이것은 게임을 멀티 플레이어로 만들기로 결정한 경우 매우 유용합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다