A GameControlManager?



  • I am trying to substitute this:

    if (FlxG.keys.anyPressed(["RIGHT","D"]) || this._vPad.buttonRight.status == FlxButton.PRESSED)

    For something like this:

    if(TBGamePad.rigth.pressed)

    What I did so far:

    typedef TBGPButton = { justPressed : Bool , pressed : Bool , justReleased: Bool }
    
    class TBGamePad extends FlxObject
    {
    
    	public static var right:TBGPButton = { justPressed : false , pressed : false , justReleased: false };	
    
    }
    
    override public function update(elapsed:Float) {
    		
    	super.update(elapsed);
    		
    	if (FlxG.keys.anyPressed(["UP"])) {
    		up.pressed = true;
    	}else up.pressed = false;
    	
    }
    

    But it is not working. Maybe I not haxing correctly.



  • I think I need to add(TBGamePad) in some state to the update run.
    But I do not want that. I want something like FlxG... functions. Which I can acess anytime.



  • @lufemas if you don't want to add it, you can make static it. Then call it from PlayState's update.

    Example:

    override public function update(elapsed:Float){
       super.update(elapsed);
       ..
       ..
       TBGamePad.update();
    }
    

    But this "update()" not overrided class update, it is custom update function where you are checking the keys.

    We are making a MMORPG w/HaxeFlixel => Click Here to go to the Facebook Page

    0


  • @eminfedar

    Thanks.

    First, how do you format to show as a code your answer.

    Well, I do not need to extends FlxBasic or FlxObject so.

    There is not static new or create function?



  • I didn't try but you can make like this:

    package;
    
    class TBGamePad
    {
    	public static var right:TBGPButton = { justPressed : false , pressed : false , justReleased: false };
    	
    	public static function update() {
    		if (FlxG.keys.anyPressed(["RIGHT"])) {
    			TBGamePad.right.pressed = true;
    		}else TBGamePad.right.pressed = false;
    	}
    
    }
    
    typedef TBGPButton = { justPressed : Bool , pressed : Bool , justReleased: Bool }
    
    

    Or customize it as you want.

    We are making a MMORPG w/HaxeFlixel => Click Here to go to the Facebook Page

    0


  • WORKING!!

    You got it right. Thanks.



  • @lufemas You're welcome ;)

    We are making a MMORPG w/HaxeFlixel => Click Here to go to the Facebook Page

    0

Log in to reply