Comments on: Simple drag and drop with snap-to-tiles in XNA XNA tutorials, code and games Fri, 10 Aug 2018 04:55:21 +0000 hourly 1 By: admin Thu, 12 Mar 2015 07:22:33 +0000 Hi Ludo :)

If you read the article to its end, you'll see that the code to make the chess board is under the heading: "Another noteworthy codesample".
If that doesn't make sense, just ask again :).

Kind regards - Jakob

By: repstyle Tue, 10 Feb 2015 19:23:23 +0000 Hello, thnaks for this tutorial but i don't understand how you create and use the grid shown in the video. Can you explain it ?

By: admin Tue, 25 Jun 2013 05:46:37 +0000 Hi Tiwi :)

You could solve it this way:
- have a list of all selectable items in the market (you probably already have this)
- when the user clicks the mouse, run through the list of items till you find the item hit (or none, in which case you do nothing :))
- if the user clicked an item:
- toggle the item's "Selected" property (something you need to code yourself)
- maybe alter the drawing of the items when they are selected. Put a border on them, or something like that? :)
- have a list of selected items which you add the selected items to when you select them, and remove the items from when you deselect them
- if the user starts dragging (moving the mouse while the mousebutton is down on top of an item), in every Update() move all the items in the "selected list" the same amount as the mouse has moved since last Update (store the old mouse position at the end of every Update(), so you can calculate the change in movement).
- when the user releases the mousebutton, check to see where that is, and if it is in an "action area" (e.g. Shopping basket, sell area, etc.) then perform the needed action. If releasing the items in an invalid location should result in the items returning to their original position, then you will need to store their original position somewhere as well :)

Note: if your items can overlap you will need to search down through them for mouseclicks from the opposite end of the list as the direction you are drawing them in. So the last drawn (the ones visually on top) will be the first to be hit with the mouse.

Hope this helps! :)

Kind regards - Jakob

By: Tiwi Tue, 25 Jun 2013 02:09:21 +0000 i want to clicking on each of them to add them to the selected images...

it's like a mini market game, there are some goods... i choose the goods and put it in the basket...
how can i make the code like that?
thanks before... 😀

By: admin Mon, 24 Jun 2013 08:23:52 +0000 Hi Tiwi :)

How would you like to select those multiple images?
Clicking on each of them to add them to the selected images, or drag a selection rectangle around them?
Write a bit more and I'll see if I can come up with some help for you :)

Kind regards - Jakob

By: Tiwi Mon, 24 Jun 2013 08:02:39 +0000 hi..i am a new learner of xna game studio and i've learn to drag and drop a multiple images..
how can i make a code to drag and drop some images in this source code?
or in this code just can to drag and drop only one images?

thanks for your help :)

By: admin Thu, 27 Dec 2012 21:08:40 +0000 Yup - sure, mail me and I'll take a look :)


By: Dnec Wed, 26 Dec 2012 14:26:13 +0000 Good tutorial I have some doubts about the code.
As much as we have strictly followed your tutorial I cant run correctly the program.
I can drag the tiles, but I can not make it stay in the square. The red color does simple not appear. I can send my source, for you take a look?