haXe Forum > haxe.Timer in C++

  • I'm trying to get haxe.Timer to work in C++, but I'm having some trouble. I made a simple class to test with.

    package;
    
    import haxe.Timer;
    
    class CPPTimer {
        private var _appTimer:Timer;
        
        public function new() {
            _appTimer = new Timer(300);
            _appTimer.run = function():Void {
                trace("called!");
            };            
        }
        
        static function main():Void {
            new CPPTimer();
        }
    }

    This code doesn't seem to work when compiled as C++ when I run the executable. The program ends run after it starts and doesn't trace anything out. However, this same code works fine when compiled as a swf. Am I missing something specific that needs to happen when targeting C++?

  • Maybe because c++ programs will exit right after everything in main() is executed, unlike Flash exit only if you closed the window. So what you can try is to add the follow at the end of main():

    while (true){}

  • Maybe its better to use cpp.Sys.sleep(a_few_milliseconds) within the loop to keep cpu consumption lower.

  • I believe I've had a similar issue a while back, I'm fairly sure I solved it by using the neash class for the timer, they seem to operate the same so all you'll need to do is replace with

    import neash.Timer;

< Prev | Page 1 / 1 | Next >