Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Creating a more sophisticated touch detection system — Gideros Forum

Creating a more sophisticated touch detection system

Hi all,

I am currently developing a mobile game using Gideros and had a question regarding improving, or adding on to the existing touch detection Gideros offers through their Touch Events.

My game requires that two Bitmaps are placed on the scene tree in very close proximity to each other (position wise), and both have touch event listeners associated with them.

Basically if I tap or swipe on a certain bitmap, I want that bitmap to respond accordingly (exact response is not relevant for this question). However I am finding that when I test the code on my phone, if I accidentally start my swipe outside of the intended bitmap, it does not register as a touch (obviously) and often times will mistake which bitmap I intended to interact with. This issue is not visible when using the computer simulation, as the mouse is much more accurate than a human finger.

Essentially what I am wondering is if anyone has needed to implement a similarly sophisticated touch detection system in a game or application they have made, and if so, what advice or suggestions they would have. Thank you for any information you can provide!

Comments

  • you should define (for yourself and for us) what behaviour you want to achieve.

    at first i'd try to make the bitmaps slightly bigger (with invisible frames) and then the touch is detected on their proximity as well.
  • Hi Keszegh, thank you for your response.

    In my game, I have several block images which have been incorporated into bitmaps positioned in a starting level position. If a user swipes a block in a specific direction and the path forward is clear of other bitmaps, each block will respond by traveling (position wise) along the specified swipe path.

    I have successfully implemented the code that will make the block travel, my issue is more with incorrectly identifying which block bitmap the user has swiped (whether that be because the finger's initial touch was inaccurate or accidentally touched the block beside it).

    I agree with you that making the bitmaps larger would certainly help solve my issue. However, due to size limitations on the screen I am not able to make my bitmaps larger, while still maintaining the same game layout.
  • keszeghkeszegh Member
    Accepted Answer
    to avoid accidentaly touches, you can do the opposite of what i recommended. namely, add a (e.g. a 0.9 size) smaller dummy object (a Pixel, or a copy of the bitmap) to every bitmap with the same center which has alpha=0 and then check touches for these. this way if one just touches the area close to two bitmaps then none of them will receive the touch, so the user has to touch them 'in the middle' and then there is no accident.
    you can also make a custom hitTestPoint function to achieve the same effect without the dummy objects, this would be more performant but needs a bit of thinking to implement.

  • SinisterSoftSinisterSoft Maintainer
    Accepted Answer
    No, register the touch event on the stage, then search through the sprites and see which has the initial touch, then when you get a move then you know which to move for that touch id. Release on the end event.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Yes I was thinking of doing something like that, except I would also like to correctly determine which block the user would like to move, even if they accidentally start their swipe outside the desired bitmap. I have an idea on how I will do that, which will involve having multiple "focus" flags, one for if a touch has been registered at all in the level scene, and one for each specific block, indicating whether it has been touched or "dragged through". Essentially, I would have to collect the touch data points, and somehow use that data to determine which bitmap has registered the most data points in its proximity (how many times hitTestPoint has registered). I will continue to work on it, I was just curious if maybe someone had written a plug in or library that enhanced the already existing touch handling system in gideros.

    Thanks for your answers.
  • Just to add on to my previous comment, and make my data collection idea clearer: let's say I have two bitmaps beside each other and I want to swipe the right-hand bitmap in such a way that it travels sideways to the right. In the case where my finger accidentally STARTS on the LEFT HAND bitmap, my intended functionality will not work with the current touch structure. What will happen is the hitTestPoint will register for the left hand bitmap's ID and it will attempt to move the left hand bitmap to the right which isn't possible.

    However, with my new system, you would collect the touch data points, and because I am swiping to the right, when I released my finger, more data points will have registered on the right hand bitmap as opposed to the left, thus correctly determining which block the user MEANT to swipe. I know there is alot of issues with this as well, but I'm just trying to start somewhere and improve as I run into bugs.
  • if you do this way, then nothing will move until you release the touch, which i think is not a very natural behaviour.

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • It actually looks pretty good and is hard to tell that block only starts moving when finger is released. Definitely something to keep in mind though.
Sign In or Register to comment.