我建立我的第一个盘点,我希望它像任何其他库存基本就是工作:如何处理项目库存
- 当你拿起东西就会把它添加到您的库存的你以后可以装备。
- 它的外观和功能类似于疯狂神的库存领域。
我得到了一些基本的东西,如做:
- 绘图库存插槽,当你鼠标移到他们改变的质感。
- 用鼠标移动项目/对象。
就是这样。
所以,现在我被卡住了涉及如何处理项目的部分,我知道有几种方法来处理项目,但我不知道在当前代码中执行它的最简单方法是什么正在使用。
如果任何人都可以指引我走向正确的方向,我会非常感激,它会为我节省很多时间!
下面的代码BTW:
class InventorySlots
{
Texture2D box;
Texture2D blackbox;
Texture2D empty;
const int offSet = 100;
Rectangle[,] Inventoryslots = new Rectangle[6, 4];
Rectangle testrect; // Rect for moving item
bool isMoving;
public void LoadContent(ContentManager Content)
{
box = Content.Load<Texture2D>("Box");
blackbox = Content.Load<Texture2D>("boxselected");
testrect = new Rectangle(10, 20, box.Width, box.Height);//Set up my test rect
empty = box;
for (int x = 0; x < 6; x++)
{
for (int y = 0; y < 4; y++)
{
Inventoryslots[x, y] = new Rectangle((x * box.Width) + offSet, // Setup my inventory slots
(y * box.Height) + offSet, box.Width, box.Height);
}
}
}
public void Update(GameTime gameTime)
{
if ((ButtonState.Pressed == Mouse.GetState().LeftButton))
{
if (testrect.Intersects(new Rectangle(Game1.mousePosition.X, Game1.mousePosition.Y, 0, 0)))
{
isMoving = true;
}
}
else
{
isMoving = false;
}
if (isMoving)
{
testrect = new Rectangle(Game1.mousePosition.X - testrect.Width/2, Game1.mousePosition.Y - testrect.Height/2, testrect.Width, testrect.Height);
}
}
public void Draw(SpriteBatch spriteBatch)
{
for (int x = 0; x < 6; x++)
{
for (int y = 0; y < 4; y++)
{
if (Inventoryslots[x, y].Contains(Game1.mousePosition))
{
empty = box;
}
else if (!Inventoryslots[x, y].Contains(Game1.mousePosition))
empty = blackbox;
spriteBatch.Draw(empty, Inventoryslots[x, y], Color.White);
}
}
spriteBatch.Draw(box, testrect, Color.White);//Draw my test item that i can move around
}
}
这样做更有意义,并希望能让我走上正轨,谢谢! – Iskalder