A question about touch movement and onscreen buttons

bloomerbloomer Member Posts: 53
edited February 2012 in Working with GS (Mac)
Hi guys. This is my first real tech question on these forums.

I have a game with a 'touch the screen to go there' movement scheme for your character. The touch just has to be outside the PC to register.

I've also got a button at the top left corner of the screen which lets you toggle between the 'touch' movement scheme and an onscreen joystick/thumbpad scheme.

The problem is, when you touch the toggle button, it also registers as a movement touch, and sends your character moving towards the topleft corner of the screen.

I created a boolean 'block movement' attribute which, when true, stops movement touches from being registered. The thing is, even if I set this to true at the moment a player presses the toggle button, their character still has time to take a tiny step towards the topleft corner of the screen before the safeguards kick in and stop them moving. I then experimented with delaying the registering of the movement touch by fractions of a second, but even at 0.5 seconds (which I consider to be too long, anyway) the safeguards can't stop the player in time.

Is there another workaround or technique for this kind of thing someone could suggest?

One thing I thought of but had to discount was having a kind of 'carpet' object underneath everything which would specifically register the movement touches. This would solve the button problem, but I've got other mechanics in the game for which it's necessary to be able to click on a scenery object and start walking towards it - so I had to forget this scheme.

Thanks for your input.

Comments

  • CloudsClouds Member Posts: 1,599
    edited February 2012
    When the toggle button get's pressed change the 'creeping' actor's velocity to 0 ?
  • bloomerbloomer Member Posts: 53
    Nods. When it's pressed, I'm already turning on a game attribute (Halt Signal) which, when true, stops all movement on the original actor. But that process doesn't occur instantaneously. The creep occurs during the time it takes for that to happen.
  • bloomerbloomer Member Posts: 53
    Any other ideas guys? Surely someone else has had to try to prevent a character from following a click occurring on a control button on their screen?
  • simo103simo103 Member, PRO Posts: 1,331
    edited February 2012
    @bloomer .. have you seen TSB's video on touching overlapping actors: http://gshelper.com/?p=268. If so and if that is the method you are using, might you check the layers those actors are in to make sure the button is uppermost? Hope that helps somehow.
  • LiquidGameworksLiquidGameworks Anchorage, AKMember, Sous Chef Posts: 956
    @bloomer Do you expect your users to ever want to click that high on the screen for movement? If not, you could do something like "if touched" and "mouse.position.y <300(or whatever number is right below your button) = move. That way, someone pressing the button won't trigger the movement.
  • bloomerbloomer Member Posts: 53
    Thanks guys. Just after I posted my last question, I restarted scanning the forums and found mention of tshirtbooth's overlapping video. I'm watching it now. Will let you know how I get on... cheers for the pointers and ideas!
  • bloomerbloomer Member Posts: 53
    edited February 2012
    So how it went - After trying lots of mechanisms in the game, then tearing them out when they didn't solve the problem, the one idea I found I needed to keep from tshirt's 'overlapping' demo was the idea of running a little timer after the player clicks on a spot to go to before actually sending them towards that spot. That gives the game time to register changes in other attributes which can block the player's move. 0.2 seconds did it. This is imperfect (there'll be some sensitive movement parts in the game, so even a little delay might be annoying at such baddie-doding moments) but it seems to be the best solution I can find in GS for now.
  • Rob2Rob2 Member Posts: 2,402
    edited February 2012
    I've done a little demo that may help.. hold on a sec

    http://bit.ly/xOb9mY the joystick isn't included but hopefully the switching logic is ok
  • bloomerbloomer Member Posts: 53
    Thanks a lot Rob. Right, so your approach was that instead of denying permission when the button's clicked, you grant permission when the button's not being clicked. And you're using a carpet to receive the actor-moving clicks.

    I've got several toggling buttons, so I could try setting up a system where if you're clicking on any of them, the others can't grant permission. I'll try this out.
  • bloomerbloomer Member Posts: 53
    Awesome - yeah, the grant permission system works instantly while the deny permission system doesn't. This business has been doing my head in for a few days and you've fixed it for me. Cheers.
  • Rob2Rob2 Member Posts: 2,402
    Pleased it solved your problem :)
  • bloomerbloomer Member Posts: 53
    Doh - okay I thought it was solved but it wasn't :) I discovered that once this system is operating with more than one button, it's not failsafe.

    In your demo, you've got an either/or situation. You're clicking inside the button or outside. That is failsafe.

    I modified it so each of the two buttons on my screen sets its own attribute when its down. Then, if you click outside one, it checks that the other one's touch attribute is also clear before it grants permission. The trouble is, the click outside registers microscopically faster than the buttons' ability to change their own status to 'DOWN', so it is still tricked into granting permission. This was tricky to bugtest - I found that removing both buttons from the game and adding them back in reverse order changes which one fails to switch fast enough. But the points is - with more than one, later ones don't change quickly enough.

    I also tested if the order that objects are layered could help, but it doesn't. Putting a touch receptacle beneath the buttons, that receptacle can still receive a click faster than the button you're clicking through to reach it can change its status to TOUCHED.

    So I still haven't worked out a way to do this with attributes. I may need to look at things like putting the buttons right next to each other and manually locking out a portion of the screen by coordinates, like earlier folks suggested.
Sign In or Register to comment.