Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7587879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:47:06+00:00 2026-05-30T19:47:06+00:00

I have a game. It has a Level class for drawing the level, managing

  • 0

I have a game. It has a Level class for drawing the level, managing blocks, etc. I also have a Tile class for each individual tile (type, x, y), and a block class for the type of block.

I get the error:

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;

Here is my 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;
    }
}
}

And block.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;
    }
}
}

I’m not even sure if its an efficient way to make a new tile(blockType,x,y) for every block on the grid. Any help would be appreciated. Mainly; How can I get the value of blockType.Dirt_Block.Texture? But I get the error about something not being static or whatever.

http://pastebin.com/s50AB6kz

EDIT: Looking back at this I feel really stupid, but I will leave it here since obviously 10k views means it has helped someone

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:47:07+00:00Added an answer on May 30, 2026 at 7:47 pm

    This code is not legal, because an enum member can only have an integer value.

    public enum BlockType
    {
         Dirt_Block = new Block("Dirt Block",,BlockCollision.Impassable,250,0,0)
    }
    

    Dirt_Block is a static member of the BlockType type, so you can’t access the Dirt_Block member on an instance of BlockType.

    And I think you misunderstand what enums are; enum members can’t have enums of their own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a game which have 5 class/level.Each class contain almost same variables.Now i
I have to simulate a game where each player has turns and needs to
If have I have a game engine that has multiple threads that all work
I have this game where balloons are coming from bottom and player has to
I have a game I'm writing in java, it has the functionality to save
I'm developing a game. I want to have game entities each have their own
I have two Activities, both have an inner class SurfaceView, which has an inner
For my level editor in my game, I have a floodfill function. The map
I am developing a game that uses a different controller for each level. It
I'm making a game right now and pretty much everything has its own class.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.