Comments on: Simplified XNA drag and drop http://xnafan.net/2013/07/simplified-xna-drag-and-drop/ XNA tutorials, code and games Fri, 10 Aug 2018 04:55:21 +0000 hourly 1 https://wordpress.org/?v=4.2.22 By: admin http://xnafan.net/2013/07/simplified-xna-drag-and-drop/comment-page-1/#comment-264803 Fri, 21 Nov 2014 08:26:15 +0000 http://xnafan.net/?p=1073#comment-264803 Super, glad to hear it! :)
If you feel like it, send a link to whatever you're working on, if you finish it.
It would be fun to see :).

Kind regards - Jakob
P.S. Sorry for the late answer, for some reason WordPress stopped notifying me of comments ... :-/

]]>
By: Jesse http://xnafan.net/2013/07/simplified-xna-drag-and-drop/comment-page-1/#comment-253031 Tue, 04 Nov 2014 12:53:24 +0000 http://xnafan.net/?p=1073#comment-253031 Jakob. Thank you very much for that tile swap demo. Helped me a lot!

]]>
By: admin http://xnafan.net/2013/07/simplified-xna-drag-and-drop/comment-page-1/#comment-96854 Sun, 02 Feb 2014 07:25:50 +0000 http://xnafan.net/?p=1073#comment-96854 Hi again Frendy :)
I've made a small codesample for you to show you how to swap the positions of two items in a grid:

http://www.xnafan.net/downloads/_tutorials/dragandswap/dragandswaptotilessolution.zip

Kind regards - Jakob

]]>
By: admin http://xnafan.net/2013/07/simplified-xna-drag-and-drop/comment-page-1/#comment-96650 Fri, 31 Jan 2014 10:05:45 +0000 http://xnafan.net/?p=1073#comment-96650 Hi Frendy :)

*** I KEY ***

I am guessing you want to show an inventory when the "I" key has been pressed? And then remove it again when the "I" key is pressed again?

For this you will need a boolean variable (e.g. "inventoryVisible"), which you toggle when the "I" key is pressed.
The easiest way to do this is:

inventoryVisible = !inventoryVisible;

which takes the opposite value of what is in the boolean variable and stores it again.

You will need to store both the current KeyboardState and the previous KeyboardState to make sure you don't just toggle (switch values) for every Update(), but only when "I" key was up in the previous Update() and down in this one.

*** Swap items ***
For this to work, you will have to
- store the original position of the item you grab with the mouse
- check when you drop an item, whether it is on top of another one

One way to check for overlap when dropping is to create two bounding rectangles, one for each item, and use the Rectangle.Intersects method (http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle.intersects.aspx) to check whether one item overlaps the other.
This way you can just set position of the item that is being dropped on to the original position of the dragged item.
If you want all items to stay in a grid, have a look at the Drag and Drop with snap to tiles tutorial:
http://xnafan.net/2012/07/simple-drag-and-drop-with-snap-to-tiles-in-xna/

Kind regards - Jakob

]]>
By: Frendy http://xnafan.net/2013/07/simplified-xna-drag-and-drop/comment-page-1/#comment-96550 Thu, 30 Jan 2014 09:53:12 +0000 http://xnafan.net/?p=1073#comment-96550 Hai sir, thank you for your drag and drop, it is very useful for me, because i wanted to make the inventory system.

But, i have a couple of questions to you.

How do you make the items will be visible only if the I in the keyboard is pressed? and how do you make when the item 1 in the inventory is dragged to the item 2, the item 2 will be moving to the item slot 1 instead of they are overlapping each other.

I am looking forward for it.. Thank you very much 😀 😀

]]>