B. UI
UI is a part that players can directly watch and interact,
which has a lot to do with the quality of the game. In order to
present a nicer and fluent interface, we need not only to write
high quality code, but to make great efforts in art design and
animation.
The main UI is shown as Fig. 4. It is a 2D interface
extending from the View class. To present such an interface,
the first thing for us to do is setting a background by calling the
setBackgroundResource() method. Then, in the onDraw()
method of the Canvas class, we call the drawText() to draw
texts as well as call the drawBitmap() to draw bitmaps on the
canvas. A Paint object is instantiated so as to set the parameters
of the text such as size and color, with the createScaledBitmap()
method called for initializing the size of the bitmap. Finally, we
present the texts and bitmaps on the background by calling the
invalidate() method, whose role is popping previous view off
819
the UI thread queue. This means that, whenever we want our
canvas to be redrew, we call the invalidate() method, with the
Android framework calling the onDraw() method for us. But
notice that the invalidate() method, which is necessary to be
employed in the main UI thread, must not be directly called in
a worker thread.
B. UIUI is a part that players can directly watch and interact,which has a lot to do with the quality of the game. In order topresent a nicer and fluent interface, we need not only to writehigh quality code, but to make great efforts in art design andanimation.The main UI is shown as Fig. 4. It is a 2D interfaceextending from the View class. To present such an interface,the first thing for us to do is setting a background by calling thesetBackgroundResource() method. Then, in the onDraw()method of the Canvas class, we call the drawText() to drawtexts as well as call the drawBitmap() to draw bitmaps on thecanvas. A Paint object is instantiated so as to set the parametersof the text such as size and color, with the createScaledBitmap()method called for initializing the size of the bitmap. Finally, wepresent the texts and bitmaps on the background by calling theinvalidate() method, whose role is popping previous view off 819the UI thread queue. This means that, whenever we want ourcanvas to be redrew, we call the invalidate() method, with theAndroid framework calling the onDraw() method for us. Butnotice that the invalidate() method, which is necessary to beemployed in the main UI thread, must not be directly called ina worker thread.
การแปล กรุณารอสักครู่..
