0
申し訳ありませんが、XNAを使ってパックマンゲームを作成する方法についてのチュートリアルは、https://www.youtube.com/watch?v=TN3NYT_glmgです。私は最大3つのチュートリアルを見て、問題に遭遇しました。 私はまさに男がしていることに従っていますが、問題はあります。私のスプライトは私の画面に描かれません。私はチュートリアルをトレースして、私が逃したものを見つけようとしました。 あなたの助けに感謝して、私はゲームプログラミングが実際にどのように動作するかを理解するために、このゲームを完了する必要があります。ここ はコード私のLoadContent関数が私のスプライトをロードしない(パックマンゲームを構築する)
オブジェクトクラスは
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace WindowsGame1
{
class Obj
{
public Texture2D Texture = null; //texture of object;
public string TextureName = string.Empty;//name of texture
public Vector2 center = Vector2.Zero;//Center of texture
public Vector2 position = Vector2.Zero;//Postion of object
public float Rotation = 0.0f; //Rotation of Object
public float scale = 1.0f; //Scale of the object
public float speed = 0.0f; //speed of the object
public bool isAlive = true;
public Obj(Vector2 pos)
{
position = pos;
}
public Obj()
{
}
public virtual void LoadContent(ContentManager Content)//Loads Content
{
Texture = Content.Load<Texture2D>("Sprites/"+this.TextureName);
center = new Vector2(Texture.Width/2, Texture.Height/2);
}
public virtual void Update(GameTime gameTime)//Updates the gametime
{
}
public virtual void Draw(SpriteBatch spriteBatch)//Draws object/sprites
{
if (isAlive)
return;
spriteBatch.Draw(Texture, position, null, Color.White, MathHelper.ToRadians(Rotation), center, scale,SpriteEffects.None, 0);
}
}
}
アイテムクラス
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace WindowsGame1
{
class Items
{
public static List<Obj> Objlist = new List<Obj>();//Create list of objects
public static Pacman Pacman;
public static void Initialize()
{
Objlist.Add(Pacman=new Pacman(new Vector2(250,250), "Pacman1"));
}
}
}
パックマンクラス
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace WindowsGame1
{
class Pacman:Obj
{
public Pacman(Vector2 pos, string textureName)
{
TextureName = textureName;
position = pos;
isAlive = true;
}
}
}
です
そして最後に ゲームクラス
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 WindowsGame1
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
Items.Initialize();
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
foreach (Obj o in Items.Objlist)
{
o.LoadContent(Content);
}
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
foreach (Obj o in Items.Objlist)
{
o.Update(gameTime);//updates all ojects
}
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)//Used to draw the game
{
GraphicsDevice.Clear(Color.SkyBlue);//This line here is used to change the color of the screen
spriteBatch.Begin();
foreach (Obj o in Items.Objlist)
{
o.Draw(spriteBatch);
}
spriteBatch.End();
base.Draw(gameTime);
}
}
}
Woah !!!ありがとう、たくさんの男! ありがとうございます(Y)。 –