java - ui / worker - thread communication -
i started android studio. making game. read should separate ui , game logic / rendering on different threads. have class game extends activity running on ui-thread. game has handler , game view class. game view game world, run on separate thread i.e worker thread. trying wrap head around how communicate between these, since example need update health bar on ui thread when player takes damage on worker thread.
fortunately have reference handler in game view class, should able communicate between these. issue publish takes log record parameter need deciphered in other end using switch. instead practice create custom handler has appropriate methods this:
this.handler = new customhandler() { public void updatehealthbar(int damage) { //find ui element , update ... } ...other methods @override public void publish(logrecord logrecord) { } @override public void flush() { } @override public void close() throws securityexception { } }; instead of this:
this.handler = new customhandler() { @override public void publish(logrecord logrecord) { switch(logrecord.message()) { case "update health bar": //find ui element , update ... ... check other cases } } @override public void flush() { } @override public void close() throws securityexception { } }; how integer value should update ui logrecord? need 1 variable says update value says how much...
Comments
Post a Comment