그래서 HealthPickup 클래스와 Player 클래스가 있습니다. 각 클래스에는 다음과 같은 코드 행이 있습니다.히트 박스를 만드는 중 오류가 발생 했습니까?
public static Rectangle Hitbox = new Rectangle(Pos.X, Pos.Y, Tex.Width, Tex.Height);
내 질문은 왜 플레이어 클래스에 오류가 있고 HealthPickup 클래스에 오류가 있습니까? 편집 : 나는 플레이어 hitbox 이상의 단계 HealthPickup 같은 오류가 발생합니다. 그것은 내 사각형 함께 할 수 있습니까?
System.TypeInitializationException was unhandled
HResult=-2146233036
Message=The type initializer for 'TestGame.Player' threw an exception.
Source=TestGame
TypeName=TestGame.Player
StackTrace:
at TestGame.RPG.LoadContent() in C:\Users\Pyroglyph\Documents\Visual Studio 2010\Projects\TestGame\TestGame\TestGame\RPG.cs:line 41
at Microsoft.Xna.Framework.Game.Initialize()
at TestGame.RPG.Initialize() in C:\Users\Pyroglyph\Documents\Visual Studio 2010\Projects\TestGame\TestGame\TestGame\RPG.cs:line 33
at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
at Microsoft.Xna.Framework.Game.Run()
at TestGame.Program.Main(String[] args) in C:\Users\Pyroglyph\Documents\Visual Studio 2010\Projects\TestGame\TestGame\TestGame\Program.cs:line 15
InnerException: System.NullReferenceException
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=TestGame
StackTrace:
at TestGame.Player..cctor() in C:\Users\Pyroglyph\Documents\Visual Studio 2010\Projects\TestGame\TestGame\TestGame\Player.cs:line 20
InnerException:
편집 : 나는 오류를 중지하지만, 난 여전히 코드를 실행 여부 결정() 나는 Console.Beep을 사용하고, 충돌 감지를 필요로하는 오류는 다음과 같은 수행을 자세히 설명한 TypeInitializationException이다. 그리고, 더 많은 코드 : 무승부
public class HealthPickup : Microsoft.Xna.Framework.GameComponent
{
public static Texture2D Tex;
public static Point Pos = new Point(50, 50);
public static Rectangle Hitbox = new Rectangle(Pos.X, Pos.Y, 32, 32);
public HealthPickup(Game game) : base(game) { }
public override void Initialize() { base.Initialize(); }
public override void Update(GameTime gameTime)
{
//if (Tex.Bounds.Intersects(Player.Tex.Bounds)) //was testing other collision-detection methods
//{
// Console.Beep(); //the only way I can check if it's being run or not
//}
}
}
() 요청에 따라 :
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 TestGame
{
public class Player : Microsoft.Xna.Framework.GameComponent
{
public static Texture2D Tex;
public static string Dir = "D";
public static Point Pos = new Point(GraphicsDeviceManager.DefaultBackBufferWidth/2, GraphicsDeviceManager.DefaultBackBufferHeight/2);
public static int speed = 4;
public static Rectangle Hitbox = new Rectangle(Pos.X, Pos.Y, Tex.Width, Tex.Height);
public Player(Game game): base(game) { }
public override void Initialize() { base.Initialize(); }
public override void Update(GameTime gameTime) { }
}
}
플레이어 클래스 코드를 게시 할 수 있습니까? 그게 문제가 아니라 다른 것을 포함하고 있기 때문입니다. 감사. –
@Fuex 저는 현재 PC에 없지만, Player 클래스 (모바일 앱 사용)로 내일 다시 보겠습니다. – Pyroglyph
@Fuex 좋아요. 'Player.cs' 코드가 게시되었습니다! 내게 비판 할 수있는 것을보고 보라. :) – Pyroglyph