Author Topic: iOS Platformer Controls  (Read 3174 times)

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
iOS Platformer Controls
« on: February 17, 2013, 12:26:14 AM »
Is it possible to create platformer controls with ngui?

OnHover() isn't available ...the idea is to be able to toggle a state like moveLeft and moveRight on 2 buttons without having to lift a finger off the screen. Any ways to do this?

Game needs a left and right arrow and on the right side of the screen a jump button, so all multitouch.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: iOS Platformer Controls
« Reply #1 on: February 17, 2013, 02:47:52 PM »
There are a million ways to do it; the specifications you provide are pretty vague and can be done in different ways.

Do you mean to be able to drag from one button to another?
Do you mean a "virtual joystick" on the screen?
Do you mean clicking multiple buttons at once, left and right at the same time for instance?


If the idea is simply to have 3 buttons, left, right, jump, then yes, you can use OnClick to catch taps. Or OnPress(bool pressed) if you want the event when they touch the screen rather than release.

I'm confused as to what you want OnHover for and the "without having to lift a finger off the screen".

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: iOS Platformer Controls
« Reply #2 on: February 17, 2013, 03:39:37 PM »
Given a <- and -> sitting in the bottom left of the screen as buttons and a button labeled jump in the bottom right... hope that's easy to visualize.

If OnHover() worked on iOS I could simply toggle a movement State left or right as the touch event was detected on top of the buttons, but if a user touches and holds down on <- right now and then slides their finger to the right onto the -> arrow button,  it's not detected because nGUI doesn't seem to pick up touch events "hovering" over buttons.  The touch event detects the <- arrow hit and actually never stops until you completely lift your finger off the screen.

I'm open to suggestions if I'm thinking about it all wrong honestly.  Here's a typical layout I was thinking about:

http://multiplayerblog.mtv.com/wp-content/uploads/2011/03/1000heroz_news.jpg
« Last Edit: February 17, 2013, 04:11:42 PM by Majicpanda »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: iOS Platformer Controls
« Reply #3 on: February 18, 2013, 04:24:55 PM »
Yeah, ok.

Then you turn off sticky keys in the UICamera, and use OnPress(bool isPressed) and trigger your "move right" "move Left", "jump" state when isPressed is true. Then you can slide your finger across the whole thing and it will trigger all three in turn.

Does that make sense? :)

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: iOS Platformer Controls
« Reply #4 on: March 19, 2013, 07:48:56 PM »
This doesn't appear to be working as intended.  I've tried to use this for a fruit ninja type implementation of a game I've been toying around with to learn physics and my Ortho Gamecamera has sticky keys DISABLED, UICamera on it, and I have objects with colliders flying around.  On them I've put void OnPress(bool pressed) and they don't trigger unless I click on them directly.

I'm waiting to be able to hold down my finger and if objects cross under the touch or mouse held down spot it should register a hit on the collider.

Any ideas?

Update: Needed StickyKeys off on both cameras.... didn't expect that or notice for some reason.  I want sticky keys on on my 2dGUI so that's not really the 100% intended result but it now "works".
« Last Edit: March 19, 2013, 07:57:29 PM by Majicpanda »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: iOS Platformer Controls
« Reply #5 on: March 22, 2013, 06:30:26 PM »
Hmm, do you have multiple UICameras? I think you might get double events then too.