Я начал новый проект 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
Вы ошибаетесь, заявляя, что пытаетесь получить доступ к 'Tile', который не существует. Нам понадобится больше кода, чтобы полностью помочь вам. – MyCodeSucks
Какие пространства имен находятся в Level.cs? – joe