How Can I Drag and Drop Actors & Snap Them Into Place? - Crossword Puzzle Game

emlarsen09

  • Posts: 6
Hi there!

So I am new to Stencyl and I am creating a crossword puzzle game. The objective is for the player to fill out the words in the crossword puzzle from the given letters. The letters are letter tiles which the player would, ideally, click and drag, and then snap into the appropriate place on the crossword puzzle. If the player set the letter on the correct tile in the crossword, the letter would "snap" into place. However, if their guess was incorrect, the letter would go drop back to its original spot at the bottom of the screen.

For example, if the words the player was supposed to find are, "Tie," "Kite," "Tank," "Tea," and "Ink," the given letters would be two A's, two E's, two I's, two K's, two N's and three T's. I would need to go about how to get, say, any of the three T's to "snap" to a spot where a T could go.

With some research into this already, my understanding is that I would code this by checking whether the x-center and y-center of the letter puzzle piece is close to the x-center and y-center of the intended area (region?). My letter tiles are 40x40px - please let me know if 32x32px is a better size to work with.

Thanks in advance!

bmofmc

  • Posts: 3
Hello! Not sure if this would help, but I would make it so that the player would click on a letter tile, then click on the chosen area region, making sure that there is no way to accidentally put a letter tile in the wrong area. If this is not the style you prefer and drag-and-drop better suites the game (as you have said), then you could make the letter tiles decrease in size some when dragged, then increase again when dropped onto the correct area, snapping into place if touching. I'm sorry if this did not help. I'm a newbie too. :P
Good day
Bmo

LIBERADO

  • *
  • Posts: 2720
my understanding is that I would code this by checking whether the x-center and y-center of the letter puzzle piece is close to the x-center and y-center of the intended area (region?).
Yes, but I would use simple actors instead of regions or tiles.

My letter tiles are 40x40px - please let me know if 32x32px is a better size to work with.
Both sizes are appropriate, it's just a matter of taste.

If you still haven't managed to do it, let me know and tomorrow I will give you the project file of this game.


« Last Edit: July 12, 2020, 03:36:57 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

emlarsen09

  • Posts: 6
Hi Liberado, thanks for getting back to me!

Yes, my letter blocks are actors . The crossword puzzle blocks are also actors.  My thoughts was to fill in each space by dropping an actor (letter block) on top of an actor (each white crossword puzzle block).  Thanks also for letting me know about the letter size. I have managed to get them to drag and drop and place, but without the logic to say that such a letter (or word) was correct or incorrect.

Yes, the project file would be helpful, thank you!

emlarsen09

  • Posts: 6
Hello! Not sure if this would help, but I would make it so that the player would click on a letter tile, then click on the chosen area region, making sure that there is no way to accidentally put a letter tile in the wrong area. If this is not the style you prefer and drag-and-drop better suites the game (as you have said), then you could make the letter tiles decrease in size some when dragged, then increase again when dropped onto the correct area, snapping into place if touching. I'm sorry if this did not help. I'm a newbie too. :P

Hi Bmo, thanks for your reply!

Your feedback was helpful. I like that concept as well; I'm thinking I'll try drag-and-drop first and see what that does. (I've got some of it working so far.)

Thanks again!

LIBERADO

  • *
  • Posts: 2720
I guess this is what you want:

<a href="http://static.stencyl.com/games/42448-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/42448-0.swf</a>
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

emlarsen09

  • Posts: 6
Yes, that's exactly what I want. Could you show me the code you used to get this?

Thanks again!

LIBERADO

  • *
  • Posts: 2720
You can check it in the .stencyl file attached to this post.
(File > Import Game)
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

emlarsen09

  • Posts: 6
Hi Liberado,

Thank you! So I have all the code all set up and the drag and drop for each of the letters is working. However, I am running into a couple issues:

1.) When I drag and drop the letters, especially when I move the second, third, fourth letter, etc., they stick to each other or disappear underneath. I am not sure why this is happening.

2.) When the game loads, the letters all appear in one line at 320y for some reason, instead of in two lines at the bottom of the screen.

I have attached a few screenshots showing you what I have for code:

Thanks again for all your help!

emlarsen09

  • Posts: 6
Also wanted to mention that each of the letters has 2 animations: picked and placed with the "when created make self active always and set actor value LETTER for Self to Letter A" under Events. The spaces animations are, BLANK and LETTER A.

I have also applied all the actors to either the LETTERS group or the SPACES group, respectively.

Thanks again!

LIBERADO

  • *
  • Posts: 2720
I too have experienced that problem only when I duplicate the scene.
Maybe it is a serious bug, you could report it in the Issue Tracker

« Last Edit: July 23, 2020, 09:55:21 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.