【发布时间】:2014-04-22 14:35:43
【问题描述】:
我有 2 个类引用主游戏函数中的列表。类 Block 和 MovingPlatform 都有一个包含所有对象的列表。
public List<Block> Blocks;
public List<MovingPlatform> Platforms;
我还有一个 Collision Manager 类,它使用 2 个列表来查看平台是否与块碰撞,然后使平台转向另一个方向。
然后我将列表转移到 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 ;
}
}
}
}
}
由于某种原因,我收到错误消息: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'
如何解决我的问题?
【问题讨论】:
-
你在哪一行得到错误?
-
它不允许我调试游戏,它会说你想使用最后一个版本。
-
但它仍然应该告诉您错误发生在代码的哪一行...
-
公开所有内容,然后将它们恢复为以前的可访问性修饰符,直到错误再次弹出
-
错误是不言自明的。也许您的班级
Game.Block声明为内部。
标签: c# list xna collision-detection