Drag and drop items on grid

chongyunxiang

  • Posts: 278
I'm trying to create a function where players can decorate their scene with furniture. Players can place furniture by dragging and dropping them onto the scene. But I want it to follow a grid.

Is there a behavior for drag and drop based on grid? If not, can someone point me to a tutorial on how to program that?

Thanks!

Luyren

  • *
  • Posts: 2763
When your mouse is already holding an actor, set its position like so:
1- Divide the mouse's position by the tile size (rounding up, so use the ceiling rounding method),
Code: [Select]
ceiling of: [(X of Mouse + X of Camera) / tile width]2- Multiply the result by the tile size.
Code: [Select]
result * Tile width3- Do the same with Y of mouse, Y of camera and tile height.

That will give you the corner of each tile as the mouse moves around.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

chongyunxiang

  • Posts: 278
Oh I get it, thanks! What's the difference between the Ceiling and Round? Round seems to work better for me (maybe because of the temporary asset I'm using).

Luyren

  • *
  • Posts: 2763
Ceiling means any decimal point will round up. So 2.1 will round up to 3.
Floor meas any decimal point will roun ddown. So 2.1 will round down to 2.
Round will round up with it is 0.5 or greater, and round down if it is 0.5 or smaller.
So perhaps try out with all the three options and see which one works best for you.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

chongyunxiang

  • Posts: 278
I think it's better to continue from here instead of inbox.

Regarding outlining the asset using the Actor Aura behavior, you mentioned to set the scale parameters.
Is this the scale parameter that you're referring to? I don't see where I can set the Minimum and Maximum scale parameters.

chongyunxiang

  • Posts: 278
Oh, i got it. Was looking at the wrong place...

Luyren

  • *
  • Posts: 2763
Oh, i got it. Was looking at the wrong place...
You don't have to open the behavior at all, you just have to customize the attributes when you attach it to your actors.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

chongyunxiang

  • Posts: 278
What about activating the aura? It looks like i'll have to tweak the behavior if I want to activate it the way I want it to be.

Luyren

  • *
  • Posts: 2763
There's a custom block, that's how you can activate/deactivate auras. Again, you don't need to open the behavior at all. Have you read the documentation, or the description of the behavior and its attributes? That should explain how to use it. There's also a video on the subject on my channel.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

chongyunxiang

  • Posts: 278
I read the part in the document concerning the Actor Aura that I'm using, but don't see any part that shows how to activate it. I've also watched the video on your itch.io website for the cutscene resource pack, but can't find the the actor aura part. I must have missed it.

Luyren

  • *
  • Posts: 2763
As I said, just use the custom block.
The explanation of it is here: https://www.youtube.com/watch?v=5BROU617SRE&feature=emb_logo
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

chongyunxiang

  • Posts: 278
Ah, that's the video. I kept trying to find it in the Cutscene Resource Pack.