Author Topic: Multi-touch onscreen controls  (Read 3359 times)

nngwww0

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Multi-touch onscreen controls
« on: Fri, Nov 11, 2011 »
I've searched for a few days but haven't found any posts or blogs that actually brought results.

Using flixel with Flash Builder 4.5
Making a small game that will run on android, ios, and blackberry.
I need multi-touch onscreen controls. I've tried several things so far, but none worked. Does anyone have any code that actually works? I'm not asking for theories or what should work, I want to hear from someone who has actually done it.

I wish this component was part of the standard flixel library
http://blog.flashgen.com/gaming/general-gaming-articles/virtual-controllers-for-touch-based-devices-pt-2/

OldmanBiles

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Multi-touch onscreen controls
« Reply #1 on: Sun, Nov 20, 2011 »
I've done it.
I created some native sprites to overlay my game with and then handle all the touch control inside of each individual sprite.

Code: [Select]
package UI
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.TouchEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;

/**
* ...
* @author Adam Biles
*/
public class touchButton extends Sprite
{
public function touchButton()
{
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

var s:Sprite = new Sprite()
s.graphics.beginFill(0xFF8080)
s.graphics.lineStyle(1, 0xFFFF00)
s.graphics.drawCircle(0, 0, 100)
s.graphics.endFill();
addChild(s);

s.addEventListener(TouchEvent.TOUCH_BEGIN, onBegin);
s.addEventListener(TouchEvent.TOUCH_END, onRelease);
}

private function onRelease(e:TouchEvent):void
{
}

private function onBegin(e:TouchEvent):void
{
}


}

}

You need to make sure that
Code: [Select]
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;is at the top of your code.

You can add this sprite into your code by directly accessing the stage in your FlxState with...
Code: [Select]
FlxG.stage.addChild(sprite)
You can also return the coordinates of the touch point with
Code: [Select]
e.stageX;
e.stageY;

nngwww0

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Multi-touch onscreen controls
« Reply #2 on: Mon, Nov 21, 2011 »
Thank you so much!

So far I've gotten this to work in an iPhone4 emulator. Currently I'm trying to get it to run on my iPod Touch 4G.
I'll post whatever results I get, in this thread.

nhonky

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Multi-touch onscreen controls
« Reply #3 on: Mon, Jan 9, 2012 »
ive been trying to implement some touch screen controls into something ive been working on.
but ive tried everything with this code and im probably missing something simple.
can anyone head me in the right direction with implementing touch controls for android?
cheers

Kramer

  • Member
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: Multi-touch onscreen controls
« Reply #4 on: Sat, Mar 24, 2012 »
I am having trouble with this also, I am testing it out on a PlayBook. I have the touch control overlayed on top of my game, but pressing it does nothing even though I have code in the onbegin and onrelease functions. I put "FlxG.stage.addChild(sprite)" in the playstate.

Any help would be appreciated.

Kramer

  • Member
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: Multi-touch onscreen controls
« Reply #5 on: Sun, Mar 25, 2012 »
So, this was apparently working for me all along.... it was faulty code that I made inside the functions for touch_begin and touch_end that screwed me up.

Fifikus

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Multi-touch onscreen controls
« Reply #6 on: Mon, Jul 2, 2012 »
I've searched for a few days but haven't found any posts or blogs that actually brought results.

Using flixel with Flash Builder 4.5
Making a small game that will run on android, ios, and blackberry.
I need multi-touch onscreen controls. I've tried several things so far, but none worked. Does anyone have any code that actually works? I'm not asking for theories or what should work, I want to hear from someone who has actually done it.

I wish this component was part of the standard flixel library
http://blog.flashgen.com/gaming/general-gaming-articles/virtual-controllers-for-touch-based-devices-pt-2/


Hi developers,

I have exacte the same problem. I can't implement some multitouch controls. I'm using Flashbuilder 4.5 with Flixel 2.46. I want a button or sprite to navigate my player to the left or right. The problem is that the TouchEvent.TOUCH_BEGIN dispatched only once. The best solution would be that the user holds the button so that the player would move to the specific direction. I looked at this http://blog.flashgen.com/gaming/general-gaming-articles/virtual-controllers-for-touch-based-devices-pt-2/, but don't know how to implement this within Flashbuilder. Can someone help me please?

finalsin

  • Member
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: Multi-touch onscreen controls
« Reply #7 on: Sat, Jul 7, 2012 »
Quote
The problem is that the TouchEvent.TOUCH_BEGIN dispatched only once. The best solution would be that the user holds the button so that the player would move to the specific direction.

You can add a second listener for TouchEvent.TOUCH_END and assume the button is pressed between touch beginning and ending. I'm doing that now and it's working okay, although I have a supplementary question for the OP/anyone experienced:

TOUCH_END seems to only fire when the touch has completely ended. But often this is a half-second after the player has decided to stop pressing the button. How do you get around this? At the moment the controls feel really sticky.