Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Trevortni opened this issue Jun 8, 2021 · 12 comments
Closed

Comments

@Trevortni
Copy link
Contributor

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
Copy link
Owner

britzl commented Jun 8, 2021

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
Copy link
Contributor Author

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
Copy link
Owner

britzl commented Jun 9, 2021

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
Copy link
Contributor Author

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
Copy link
Owner

britzl commented Jun 10, 2021

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
Copy link
Owner

britzl commented Jun 10, 2021

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
Copy link
Owner

britzl commented Jun 10, 2021

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
Copy link
Owner

britzl commented Jun 10, 2021

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Owner

britzl commented Jun 12, 2021

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
Copy link
Owner

britzl commented Jun 13, 2021

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

@britzl britzl closed this as completed Jun 13, 2021
Trevortni added a commit to Trevortni/defold-input that referenced this issue Aug 28, 2021
britzl pushed a commit that referenced this issue Aug 29, 2021
#24)

* Update cursor.script

Clear drag_state on release if drag_cancelled

* Update cursor.script

Fixed typo

* Update cursor.script

Actually fixed typo this time.

* Added origin_x and origin_y to drag events

As per #21

* Added event_only_drag option

As per #19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants