我已經開始了一個新的XNA項目,並且在類之間有一些問題進行通信。基本上,我正在爲基於磁貼的平臺遊戲設置框架,目前有兩個非常簡單的類。c#無法訪問解決方案中的其他類
一個類,Tile(Tile.cs)包含和枚舉,命名爲TileCollision和一個名爲Tile的結構。
其他,Level(Level.cs)。任何時候我嘗試引用TileCollision或嘗試創建Tile時,都會說它在當前上下文中不存在。
還有什麼我需要做的,讓這兩個班談?它們位於相同的命名空間中,不需要添加引用,因爲它們不是編譯DLL的或任何東西。不知道我錯過了什麼。
下面是Tile.cs代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace PoriPlatformer
{
class Tile
{
// Controls the collision detection and response behavior of a tile.
enum TileCollision
{
// A passable tile is one which does not hinder player motion at all, Example: Air
Passable = 0,
// An impassible tile is one which does not allow the player to move through it at all
// It is completely solid.
Impassable = 1,
// A platform tile is one which behaves like a passable tile except when the player
// is above it. A player can jump up through the platform as well as move past it
// to the left and right, but can not fall through the top of it.
Platform = 2,
}
struct Tile
{
public Texture2D Texture;
public TileCollision Collision;
public const int Width = 40;
public const int Height = 32;
public static readonly Vector2 Size = new Vector2(Width, Height);
// Constructs a new tile
public Tile(Texture2D texture, TileCollision collision)
{
Texture = texture;
Collision = collision;
}
}
}
}
下面是Level.cs違規代碼:
// Loads an individual tile's appearance and behavior.
private Tile LoadTile(char tileType, int x, int y)
{
switch (tileType)
{
// Blank space
case '.':
return new Tile(null, TileCollision.Passable);
// Passable platform
case '~':
return LoadTile("platform", TileCollision.Platform);
// Impassable block
case '#':
return LoadTile("block", TileCollision.Impassable);
case '_':
return LoadTile("ground", TileCollision.Impassable);
default:
throw new NotSupportedException(String.Format("Unsupported tile type character '{0}' at position {1}, {2}.", tileType, x, y));
}
}
在Level.cs下劃線部分是TileCollision
我們展示你的代碼。那個錯誤信息說了別的。 – tnw 2013-04-30 19:49:21
您錯誤地指出您正在嘗試訪問不存在的「Tile」。我們需要更多代碼才能完全幫助您。 – MyCodeSucks 2013-04-30 19:56:11
Level.cs中有哪些命名空間? – joe 2013-04-30 19:56:35