FlxGame.ticks timer use problem



  • how can i call FlxGame.ticks from FlxState update code block? code example please.
    second day can't solve timer use problem. and internet have not examples. FlxGame declaire in Main.hx file, and FlxState update codeblock placed in PlayState.hx file.


    Main.hx file

    package;

    import flixel.FlxGame;
    import openfl.display.Sprite;

    class Main extends Sprite
    {
    public var Game:FlxGame;
    public function new()
    {
    super();
    Game = new FlxGame(3668, 2323, MenuState);
    addChild(Game);

    }
    

    }


    PlayState.hx file

    package;

    import flixel.FlxG;
    import flixel.FlxSprite;
    import flixel.FlxState;
    import flixel.text.FlxText;
    import flixel.ui.FlxButton;
    import flixel.math.FlxMath;

    class PlayState extends FlxState
    {
    var _court:FlxSprite;
    var _player0:Player;
    var _player1:Player;

    override public function create():Void
    {
    	
    	_court = new FlxSprite(0, 0, "assets/images/court/court2.png");
    	add(_court);
    	_player0 = new Player(0, 0, "assets/images/players/15.png");
    	_player1 = new Player(500, 500, MenuState.ballcolor);
    	add(_player0);
    	add(_player1);
    	
    	
    	super.create();
    }
    
    override public function update(elapsed:Float):Void
    {
    	
    	if (FlxG.mouse.pressed){
    		FlxG.watch.add(Game.ticks,"elapsed");//this place need FlxGame.ticks value
    		if (FlxG.mouse.screenX > 3668 / 2){
    			_player0.x = 3000;
    			_player1.move(0,FlxG.mouse.screenX,FlxG.mouse.screenY);
    		}
    		else{
    			_player0.x = 1000;
    			_player1.move(0,FlxG.mouse.screenX,FlxG.mouse.screenY);
    		}
    	}else{
    		
    		//_player1.move(_player1.actiontimer.elapsedTime);
    		//_player1.x+=_player1.actiontimer.elapsedTime+1;
    	}
    	
    	super.update(elapsed);
    	
    }
    

    }

    ... amazing code higlighting



  • You can access the FlxGame object through the global class FlxG :arrow_left: click the link for more information

    override public function update(elapsed:Float):Void {
        var ticks = FlxG.game.ticks;
    }
    

    You must be new here! Welcome to the HaxeFlixel Forum!



  • @DleanJeans yes, i am new...thanx, few minutes ago i blind touch find this method with
    FlxG.game.ticks -> in my case this look like
    FlxG.watch.add(FlxG.game,"ticks"); for debug and value is huge!
    but i hope understand how reset this value, because it little scare me, my value now bigger than 100000000000 and is int type, and int max value 2**32 . is it will problem when i try to compile apk for android etc?
    or haxeflixel int is not int?



  • I'm wondering why you need the ticks value?



  • in time of actions(player moving, ball flying) i need count time from start of action , that calculate projection of z axis displacement(in my case sin30degrees).
    i need start point and timer, or use nowticks-oldticks and use this data calculate pseudo 3D displacement ball fly, in my case beach volleyball ball fly

    i look at FlxTimer but can't find comfort info that learn it... and i dont need callback... just need timer... i search comfort way

    -on timer
    -take the value few times
    -off timer... or destroy



  • Actually, it's not necessary to pass a callback to FlxTimer. Here's an example of FlxTimer (Haven't used it for a long time :D):

    var timer = new FlxTimer();
    timer.start(100000); // set the Time value to some big number
    
    trace(timer.elapsedTime); // get elapsed time
    
    timer.cancel(); // stop the timer
    timer.destroy(); // destroy the timer
    


  • Also the ticks value is the miliseconds since the game started.



  • @DleanJeans only now i understand, my be timer work good, in time when i use timer syntax i write wrong watch syntax, FlxG.watch.add(mytimer.elapsedTime,"dt");
    but later i find what right syntax is
    FlxG.watch.add(mytimer,"elapsedTime");
    maybe this will work. i need test, after some pause


Log in to reply