Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I handle items in inventory
    text
    copied!<p>I'm building my first inventory and I want it to work like any other basic inventory that is:</p> <ul> <li>When you pick up something it will add it to your inventory that you later on can equip.</li> <li>It will look and work similar to Realm of the mad god's inventory.</li> </ul> <p>I got some of the basic stuff done like:</p> <ul> <li>Drawing inventory slots and when you mouse over they change texture.</li> <li>Move an item/object around with your mouse.</li> </ul> <p>and that's about it.</p> <p>So now I'm stuck the part that involves how to handle items, I know that there are several ways to handle items but I don't know what would be the easiest way to do it in the current code that I'm using.</p> <p>If anyone could point me in the right direction I would be very greatful and it would save me a lot of time!</p> <p>Here's the code btw:</p> <pre><code>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&lt;Texture2D&gt;("Box"); blackbox = Content.Load&lt;Texture2D&gt;("boxselected"); testrect = new Rectangle(10, 20, box.Width, box.Height);//Set up my test rect empty = box; for (int x = 0; x &lt; 6; x++) { for (int y = 0; y &lt; 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 &lt; 6; x++) { for (int y = 0; y &lt; 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 } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload