britzl / defold-input

Simplify input related operations such as gesture detection, input mapping and clicking/dragging game objects
MIT License
111 stars 26 forks source link

Suggestion: Event-only, axis-bound, and abortable/fixed-distance dragging #19

Closed Trevortni closed 2 years ago

Trevortni commented 2 years ago

Three related ideas to make it easier to get a similar feel to swapping tiles in Candy Crush (which swaps tiles immediately on dragging half a tile, only vertically or horizontally, aborting the drag after):

First, if a flag can be set so that dragging only informs the object that a drag happened, without moving the object, then the object can handle custom responses to dragging.

For example, a flag to bind to the nearest axis would allow horizontal or vertical dragging to the nearest tile on tiled games.

And being able to send a message to abort dragging or specify an exact distance to drag can further aid getting the drag right on tiles.

I'm probably going to modify my download of the code myself to add these in, if you accept contributions.

britzl commented 2 years ago

It's an interesting and possibly quite useful suggestion. Although if operating on a grid such as in a match-3 game then I'm not even sure you need to use the cursor logic from this repository.

I offer a different approach, specifically for match-3 games here: https://github.com/britzl/emthree (demo: https://britzl.github.io/Emthree/index.html)

Trevortni commented 2 years ago

Oh yeah, I saw that one too. I wasn't quite sure how well it would work for my purposes, given that my mechanics only begin with match 3 (also, I had already completed a major portion of the more advanced logic before I noticed it - ah well).

I actually think I figured out how to do most of what I want using the cursor subscription from the game board instead of running the logic through the tiles; canceling the drag once initiated looks like it will cover the most bases, and then I can handle the more esoteric logic that I haven't described elsewhere (sorry for the vague description on that, but it's a mechanic I've never seen before, and despite it appearing rather complex to implement, I think I have a pretty good handle on it, so I want to play it close to my chest for now). I'd imagine it will be okay to have two separate cursor objects handling different targets, though?

britzl commented 2 years ago

I'd imagine it will be okay to have two separate cursor objects handling different targets, though?

Yes, that should not be a problem I think!

Trevortni commented 2 years ago

And it turns out that the message sent to listeners doesn't include the object that the cursor is dragging. I guess I've got some thinking to do about whether I want to abandon the library and do it all myself, change the library code as I initially thought, or do one of a few other workarounds that suggest themselves.

Good night! :)

britzl commented 2 years ago

And it turns out that the message sent to listeners doesn't include the object that the cursor is dragging

This is something we could add though. Sounds useful!

britzl commented 2 years ago

a flag to bind to the nearest axis would allow horizontal or vertical dragging to the nearest tile on tiled games.

Now that I think of it I must say I like this idea. It is useful in many scenarios..

britzl commented 2 years ago

This is something we could add though. Sounds useful!

I checked and the message should have a field id with the game object id of the object being dragged

britzl commented 2 years ago

Now that I think of it I must say I like this idea. It is useful in many scenarios..

Released https://github.com/britzl/defold-input/releases/tag/4.1.0

Trevortni commented 2 years ago

This is something we could add though. Sounds useful!

I checked and the message should have a field id with the game object id of the object being dragged

Well, whyever it wasn't showing up for me before, it is showing up now. Thanks!

Trevortni commented 2 years ago

This is something we could add though. Sounds useful!

I checked and the message should have a field id with the game object id of the object being dragged

Okay, I think I figured it out. It looks like the drag message gets sent even if there isn't an object associated with the event. So, if you drag empty space - or, in my case, an object that you forgot you disabled the collision for - you get a drag event without an id. Should be easy enough to throw it out if there's no id, now that I know.

britzl commented 2 years ago

Yes, the cursor supports drag operations without an underlying target object. This can be used when you want to use drag to move around on a large map for instance.

britzl commented 2 years ago

I'm closing this as we now have axis-bound drag.