AuthorTopic: Sliding a letter onto a spot (Read 4992 times)

I've figured out how to code a scene so you can slide a scene object, for example, a letter around.

It's a word game. I've done it where you have letters in a scene, take the letters into your inventory and slide them onto a specific slot for each letter to spell a word but I want to be able to not take the letters into inventory but just use them them in the scene and slide them onto slots in the scene to spell the word. If they're wrongly in the slot, that's ok, you just have to do it over.

I can slide the letters around but am having trouble getting them to stick on the slot that is meant for each one.

I can post some code tomorrow if that would help.

Just for my information, is it possible to use "on object" for example "on LetterA" in the scene if Letter A is in the scene and not in your inventory---or does "on" only work with inventory items? Thanks for any enlightenment.

I haven't exhausted every possibility but hoping someone has already done this. Thanks.

I’m using modified code from old posts from the Derman and Warmblood to make the sliding effect which works fine—my problem is getting the entity under the game selected item to change its graphic when the selected item hovers over it at the same x and y and delete the game selected item.

I don't understand the relation to inventory items. The threads you linked use scene entities. You just move the entities around with mouse.

EDIT: If I were you, I wouldn't tie the pieces to inventory items at all. Perhaps have a scene with predefined entities for each letter. Upon entering the puzzle scene, display or hide some letters depending on what the player has in their inventory. Then just use the entity shuffling code to move the letters around. Does that sound feasible?

Hi, Mnemonic--I'm not using inventory items -- just entities in the scene---I can move the entities around. I have about 9 letters in the overlay. You can slide 7 of the letters correctly onto an area where there is a blank slot to hold each letter (sprite entity) to spell the word ---the extra 2 are just red herrings---but they don't stick (snap) to the spot each is supposed to snap to.

F.E. MYSTERY

I can slide the M to the M spot but it doesn't snap in--nothing happens. Thanks for your help.

I'm not clear what you mean by display or hide some letters depending on what the player has in their inventory? Or what entity shuffling code is. Although I will search it in the forum. Thanks again.

The entity does get mouse release event using warmblood's code. The entities are pngs for letters (the entities you can move around). They should each snap into a separate slot to hold each letter to display word, f.e. mystery. I can post my code later tonight.

The entities that hold the letters are blank colored circles -- like old fashioned typewrite keys. so

Yes... but do the pngs have transparent areas? If there are holes in them, and you release the mouse button while the mouse pointer is above the hole, the entity will not receive the release event and it will not "snap". Is that the case?

Yes... but do the pngs have transparent areas? If there are holes in them, and you release the mouse button while the mouse pointer is above the hole, the entity will not receive the release event and it will not "snap". Is that the case?

Is there anyway to avoid that behavior? I have that problem for example with an inventory item, which is a thin wooden pole, so the user has to do "pixelhunting"....WHats a neat way to avoid that?

Mnemonic, could you help me here--- Right now I have the sliding effect working perfectly but trying to figure out how to test when every letter is on its right slot. Am trying to match up the X's and Y's but it doesn't seem to work.

What exactly happens when you slide a scene entity onto another scene entity (in a layer)? How can they interact? And how can you test whether they match up? MY x,y test doesn't seem to be working.

Both EntSlot1 and EntLetterM now take up the same space because I slid M onto Slot1 and their X values should match up---maybe I have to be more precise--

so everything is not fine but getting there -- will work on it somemore tomorrow in a different way : )

@Spellbreaker: To avoid that for example with a wand, I put a special effect behind or over the wand (like a flameball or puff of smoke) to graphically make it thick enough in the middle so that there's no pixel hunting--it is a pain for sure otherwise. : ) My crowbar f.e. now is a bar with a crow head curving into the bar to give it that thickness--it does get challenging!

if (EntSlot1.X==EntLetterM.X){do something because everything is fine}}

You will want to be more tolerant with the player:) This way they'd have to hit the exact spot. IMO a good and natural way is to:

1) Define the slot rectangle somehow. I don't know how your slots are done; if you are using entities for slots, then use the entity's X and Y position to define the top-left point, and add the width/height of the entity to get the lower-left point (you'll need to hardcode the width/height, because you can't read entity size in wme script).2) When the player drops the letter, check if the center point of the letter entity is within the slot rectangle.

Thanks, Mnemonic, that was very kind of you to post the code snippet---I will try it tonight but am pretty sure it will solve the problem. I use sprites for both Slots and Letters. I think with your code snippet and the link to the Derman's code for sliding, people should be able to replicate this puzzle pretty easily. Thanks for your help.Have tried the sprite/pixel precise method for inventory items and it does work. Just had to change the width of the inventory box as sprite goes up a little.

Note my new signature! It worked perfectly. Sometime by the end of this week, I'll put up a little demo in some appropriate place here of the code so anyone who doesn't know how to do this type of puzzle can do it. There must be someone other than me who didn't know how. ; )