Domanda

I have 2 classes that references a list inside the main game function. Classes Block and MovingPlatform both have a list that holds all the objects.

public List<Block> Blocks;
public List<MovingPlatform> Platforms;

I also have a Collision Manager class which uses the 2 lists to see if platforms is colliding with a block and then make platforms go another direction.

I then transfer over the lists to the class Collision Manager:

public class Collision_Manager
{
    Game1 game1;

    public void Initialize(Game1 game1)
    {
        this.game1 = new Game1();
    }

    public void Update(GameTime gameTime, Game1 game1)
    {
        this.game1 = game1;

        for (int i = 0; i < game1.Blocks.Count; i++)
        {
            Rectangle BlockBounds = new Rectangle(
                (int)game1.Blocks[i].Position.X, 
                (int)game1.Blocks[i].Position.Y, 
                game1.Blocks[i].Texture.Width, 
                game1.Blocks[i].Texture.Height);

            Rectangle top = new Rectangle((int)BlockBounds.X + 5, (int)BlockBounds.Y - 10, BlockBounds.Width - 10, 10);
            Rectangle bottom = new Rectangle((int)BlockBounds.X + 5, (int)BlockBounds.Y + BlockBounds.Height, BlockBounds.Width - 10, 10);
            Rectangle left = new Rectangle((int)BlockBounds.X - 10, (int)BlockBounds.Y + 5, 10, BlockBounds.Height - 10);
            Rectangle right = new Rectangle((int)BlockBounds.X + BlockBounds.Width, (int)BlockBounds.Y + 5, 10, BlockBounds.Height - 10);

            for (int b = 0; b < game1.Platforms.Count; b++)
            {
                Rectangle PlatformBounds = new Rectangle(
                (int)game1.Platforms[i].Position.X,
                (int)game1.Platforms[i].Position.Y,
                game1.Platforms[i].Texture.Width,
                game1.Platforms[i].Texture.Height);

                if (top.Intersects(new Rectangle(PlatformBounds.X, PlatformBounds.Y, PlatformBounds.Width, PlatformBounds.Height)) && game1.Blocks[i].BlockState == 3)
                {
                    game1.Platforms[i].Thing = false;
                }

                if (bottom.Intersects(new Rectangle(PlatformBounds.X, PlatformBounds.Y, PlatformBounds.Width, PlatformBounds.Height)) && game1.Blocks[i].BlockState == 3)
                {
                    game1.Platforms[i].Thing = true;
                }

                if (left.Intersects(new Rectangle(PlatformBounds.X, PlatformBounds.Y, PlatformBounds.Width, PlatformBounds.Height)) && game1.Blocks[i].BlockState == 3)
                {
                    game1.Platforms[i].Thing = false;
                }

                if (right.Intersects(new Rectangle(PlatformBounds.X, PlatformBounds.Y, PlatformBounds.Width, PlatformBounds.Height)) && game1.Blocks[i].BlockState == 3)
                {
                    game1.Platforms[i].Thing = true ;
                }
            }
        }
    }
}

For some reason I am getting the error: Inconsistent accessibility: field type 'System.Collections.Generic.List<Game.Block>' is less accessible than field 'Game.Game1.Blocks'

Inconsistent accessibility: field type 'System.Collections.Generic.List<Game.MovingPlatform>' is less accessible than field 'Game.Game1.Platforms'

How do I fix my problem?

È stato utile?

Soluzione

The Block and Platform classes must be public because you use them in public fields. Or you can use the same or a lower accessor for the property as the one you use in your class. For example if your class is declared internal use also internal for your field.

Altri suggerimenti

Your classes Block and MovingPlatform have lesser access than your public fields List<Block> Blocks and List<MovingPlatform> Platforms.

You probably haven't defined any access specifiers with your classes Block and MovingPlatform, so they are considered internal by default, which is less accessible then public.

You can fix the issue by making those classes as public or you can have your fields marked as internal. You should decided your access to properties/classes according to your requirement. You may see Access Modifiers (C# Reference)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top