У меня есть игра.У него есть класс Level
для рисования уровня, управления блоками и т. Д. У меня также есть класс Tile
для каждой отдельной плитки (тип, x, y) и класс блоков для типа блока.
Я получаю ошибку:
Member cannot be accessed with an instance reference; qualify it with a type name instead
In
Texture2D texture = tiles[x, y].blockType.Dirt_Block.texture;
Вот мой Tile.cs
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Game.Tiles;
namespace Game
{
public struct Tile
{
public BlockType blockType;
public int X;
public int Y;
/// <summary>
/// Creates a new tile for one position
/// </summary>
/// <param name="blocktype">Type of block</param>
/// <param name="x">X Axis position</param>
/// <param name="y">Y Axis position</param>
public Tile(BlockType blocktype,int x,int y)
{
blockType = blocktype;
X = x;
Y = y;
}
}
}
И блок.cs ...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Game.Tiles;
namespace Game.Tiles
{
/// <summary>
/// Controls the collision detection and response behavior of a tile.
/// </summary>
enum BlockCollision
{
/// <summary>
/// A passable tile is one which does not hinder player motion at all.
/// </summary>
Passable = 0,
/// <summary>
/// An impassable tile is one which does not allow the player to move through
/// it at all. It is completely solid.
/// </summary>
Impassable = 1,
/// <summary>
/// A platform tile is one which behaves like a passable tile except when the
/// player is above it. A player can jump up through a platform as well as move
/// past it to the left and right, but can not fall down through the top of it.
/// </summary>
Platform = 2,
}
public enum BlockType
{
Dirt_Block = new Block("Dirt Block",,BlockCollision.Impassable,250,0,0)
}
/// <summary>
/// Stores the appearance and collision behavior of a tile.
/// </summary>
public struct Block
{
public static string Name;
public static Texture2D Texture;
public static BlockCollision Collision;
public static int Width = 16;
public static int Height = 16;
public static int maxAmount;
public static int Worth;
public static int Strength;
public static Vector2 Size = new Vector2(Width, Height);
/// <summary>
/// Contructs a new block
/// </summary>
/// <param name="name">Name of the block</param>
/// <param name="texture">Texture to use as image</param>
/// <param name="collision">Collision type</param>
/// <param name="maxamount">Maximum amount of these blocks you can have</param>
/// <param name="worth">How much this block is worth</param>
/// <param name="strength">How hard the block is (how much you will have to hit to mine it)</param>
public Block(string name, Texture2D texture,BlockCollision collision, int maxamount, int worth, int strength)
{
Name = name;
Texture = texture;
Collision = collision;
Width = 16;
Height = 16;
maxAmount = maxamount;
Worth = worth;
Strength = strength;
}
}
}
Я даже не уверен, насколько эффективен способ сделать new tile(blockType,x,y)
для каждого блока в сетке.Любая помощь будет оценена.В основном;Как я могу получить значение blockType.Dirt_Block.Texture
?Но я получаю сообщение о том, что что-то не является статичным или чем-то еще.
http://pastebin.com/s50AB6kz
РЕДАКТИРОВАТЬ: Оглядываясь назад, я чувствую себя действительно глупо, но я оставлю этоздесь, очевидно, 10 000 просмотров означает, что это помогло кому-то