Draggable
namespace Griff.Scenes;
public sealed class Draggable : Component, IDrawEffectSomething the player picks up with the mouse and drops somewhere else: a card, a puzzle piece, an item in an inventory, a word to put in order. Press on it to pick it up (it’s drawn on top while held), let go to drop it. Dropped on a DropTarget that takes it, it lands in the target’s middle; dropped on one that doesn’t (full, or for other kinds), it slides back where it came from. With a controller or keys, a Grabber picks it up instead.
It’s picked up by its collider’s shape, or its sprite’s if it has no collider, and lands by its middle. In a network game the host moves it for whoever holds it, and two players can’t hold the same thing.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”DropMessage
Section titled “DropMessage”public string? DropMessage { get; set; }A message sent with Game.Send when it’s let go, with this entity as its data.
DropSound
Section titled “DropSound”public string? DropSound { get; set; }A sound played when it’s let go, e.g. “Sounds/drop.wav”.
public float Grid { get; set; }Let go off a target, it lands in the middle of a square this big (1 matches a tilemap’s cells), so things line up. 0 leaves it where it’s let go.
IsHeld
Section titled “IsHeld”public bool IsHeld { get; }True while someone holds it, with the mouse or a Grabber.
public string? Kind { get; set; }What kind of thing it is, e.g. “Card” or “Red Gem”: a DropTarget’s Accepts names the kinds it takes.
OnlyOnTargets
Section titled “OnlyOnTargets”public bool OnlyOnTargets { get; set; }True if it only goes on targets: let go anywhere else, it slides back where it was picked up. Otherwise it stays where it’s let go.
PickUpMessage
Section titled “PickUpMessage”public string? PickUpMessage { get; set; }A message sent with Game.Send when it’s picked up, with this entity as its data.
PickUpSound
Section titled “PickUpSound”public string? PickUpSound { get; set; }A sound played when it’s picked up, e.g. “Sounds/pick.wav”.
SlideTime
Section titled “SlideTime”public float SlideTime { get; set; }Seconds it takes to slide into place: onto a target’s middle, the grid, or back where it came from. 0 jumps.
StaysOnTarget
Section titled “StaysOnTarget”public bool StaysOnTarget { get; set; }True if it stays on the first target it’s dropped on that takes it: a jigsaw piece in its place, a word in its gap. It can’t be picked up again.
Target
Section titled “Target”public Entity? Target { get; }The drop target it’s on, or null. It’s on a target while it rests with its middle inside the target’s shape.
Events
Section titled “Events”Dropped
Section titled “Dropped”public event Action<Entity>? DroppedRaised when it’s let go, with the drop target it lands on, or null if it lands anywhere else (or goes back).
PickedUp
Section titled “PickedUp”public event Action? PickedUpRaised when it’s picked up.