Touch events in Android



  • Hello there, I am pretty new to the Haxe and HaxeFlixel Community, after completing the tutorial on the official docs AND after finishing the RPG tutorial I found here in the forums, I thought I'd try to test that tutorial on a mobile device. So I need to convert mouse clicks in my code with screen touches. I am sure it isn't THAT hard but I have struggled to find any working example involving touch events in mobile devices in HaxeFlixel, only infos about the FlxTouch class. Here's what I tried so far :

    Insead of

    if (currentAction == Walking && FlxG.mouse.justReleased)
    {
    	var tcX = Math.floor(FlxG.mouse.x / TILE_WIDTH);
    	var tcY = Math.floor(FlxG.mouse.y / TILE_HEIGHT);
    

    I tried this :

    if (currentAction == Walking && FlxTouch.justPressed)
    {
    	var touchPosition = FlxTouch.justPressedPosition;
    	var tcX = Math.floor(touchPosition.x / TILE_WIDTH);
    	var tcX = Math.floor(touchPosition.y / TILE_HEIGHT);
    

    When running

    lime test android
    

    I get the following errors:

    source/PlayState.hx:169: characters 34-54 : Class<flixel.input.touch.FlxTouch> has no field justPressed
    source/PlayState.hx:171: characters 23-51 : Class<flixel.input.touch.FlxTouch> has no field justPressedPosition
    

    Can anyone help me here ? Any working example involving touch events would do. Thanks !



  • To check touch input, you need to use FlxG.touches

    You can get the first touch with FlxG.touches.getFirst()
    Then you can call justPressed on it


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.