Author Topic: touch events?  (Read 3459 times)

zanardi

  • Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
touch events?
« on: Mon, Sep 27, 2010 »
Hello Flx.Community,

I do have a last question, Im about to finish a little game, and I do want to know: how to use touch events?

I was using touch events on flash cs5 without problems, but when I do try to do the same thing on flashdevelop, "Type was not found or was not a compile-time constant".

The flash builder does not come with that? Somebody know whats the point?

I will paste my touch code below (with adaptations and cuts):


import org.flixel.*;
import flash.system.Capabilities;
import flash.events.*
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.events.TouchEvent;

///////////////////////////////
stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
//////////////////////////////////////
private function onTouchBegin(event:TouchEvent):void {    
}
private function onTouchMove(event:TouchEvent) {       
}
private function onTouchEnd(event:TouchEvent) {
}

TestSubject06

  • Member
  • **
  • Posts: 69
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #1 on: Mon, Sep 27, 2010 »
i don't think the flex SDK has touch events yet. you may need to write those in yourself? if you have CS5 maybe you can find all of the AS3 files and copy/pasta them into the flex SDK dir? just spitballin' here.
Stuff.

zanardi

  • Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #2 on: Mon, Sep 27, 2010 »
I was looking for then on programfiles/adobe folder, but I dont know if they are there. The windows search says theres nothing, but Im not sure if that thing work right.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: touch events?
« Reply #3 on: Mon, Sep 27, 2010 »
You just need the global.swc file which is within the CS5 folder structure somewhere (run a search for it). You'll find several, one per target version. Get the 10.1 obviously.

You can then copy that into the lib folder of your FlashDevelop project, and link it in and it'll compile all the missing events just fine, and other stuff such as the bitmap surface rendering.

http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

zanardi

  • Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #4 on: Tue, Sep 28, 2010 »
Hum, nice. It is a relief to have it there.
Theres a last issue. More a doubt of mine: theres a workaround to use touch event listeners on flxSprite? of theres a better and cleaner way to do it on flixel?

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: touch events?
« Reply #5 on: Tue, Sep 28, 2010 »
No it will be impossible to use events like that on a flxsprite because they aren't real sprites and aren't on the display list. You could hack around it by having invisible real sprites or clips positioned over the flx ones, but it's a bit messy.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

zanardi

  • Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #6 on: Mon, Oct 4, 2010 »
Hum.... any sugestions to start with?
Maybe I can create an sprite on the main as game file, where it extends FlxGame? Or up of that, something that extends the Main class that extends FlxGame?

But now comes the part I dont know for sure. I,ve not got right the static const variables, how can I from these parts tell the inner classes that "left side of screen has been pressed, go to left!" ?

NoobsArePeople2

  • Member
  • **
  • Posts: 55
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #7 on: Tue, Oct 5, 2010 »
Do you really need touch events?  If you're just doing the touch equivalent of click and mouse down the good ole MouseEvent will work just fine and is probably even preferrable.

See this vid.  Around 10:00 is the discussion about MouseEvent vs TouchEvent.

zanardi

  • Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #8 on: Tue, Oct 5, 2010 »
Hum, interesting... I will watch and report later,

zanardi

  • Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #9 on: Mon, Oct 11, 2010 »
I see...

Well, I do have this game:
http://zanardiliza.com/games/gfem/
Actually it responds with arrow keys. On an android version, I do want to control the character touching the right half of the screen to the player walks right, and vice-versa.

Do mouse events works with something like multitouch for that? (because if two fingers if pressing...)
I will try to compile to my ipod touch and see if it works.

NoobsArePeople2

  • Member
  • **
  • Posts: 55
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #10 on: Mon, Oct 11, 2010 »
If you need multitouch then you'll have to use TouchEvent.  I've successfully used FlxButton on Android with AIR for Android and that uses the standard MouseEvent.  MouseEvent doesn't do any multitouch so it shouldn't matter if you hit a button with 1, 2, 3 or more fingers -- it'll all work like you hit it with one.

Unless multitouch is critical to your game I'd recommend going with MouseEvent since there is less overhead with this class.

zanardi

  • Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #11 on: Mon, Oct 11, 2010 »
Well, the thing is, I do want to put an invisible button on half screen left, and another on half screen right. If a player presses the left button, then press the right one (so the player is pressing both buttons at the same time) and the releases the left button. Theres any problem, or the mouse events work fine with that?

NoobsArePeople2

  • Member
  • **
  • Posts: 55
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #12 on: Tue, Oct 12, 2010 »
I don't think it's a problem (I don't have direct access to a device; it's a friends).  I had it set up so there were buttons for moving left, right and jumping and I don't recall there being any problems with pushing, say, the right button and the jump button at the same time.

I always start with whatever would present the least amount of work and overhead and go from there.  Since FlxButton exists already I just used that and it seems to work okay (haven't really tested it thoroughly yet).  Best bet is to try it and see.

zanardi

  • Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: touch events?
« Reply #13 on: Wed, Oct 13, 2010 »
Will do it. And report when done.