Android Advanced Notes 05:view, Surfaceview and glsurfaceview relationships and differences

Source: Internet
Author: User

1. The main addition to the control class in Android games is the display class View. Surfaceview is a Display class that derives from the View base class. The three views commonly used in Android game development are:

(1) The differences between view,surfaceview and Glsurfaceview are as follows:

• View: display view, built-in canvas, provides graphical drawing functions, touch-screen events, key event functions, etc. must be updated within the UI main thread, slower

• Surfaceview: based on View View to expand the class of views, more suitable for 2D game development; it's view . sub-class, similar to using a double-slow mechanism to update the screen in a new thread so the refresh interface is faster than the View come on.

• Glsurfaceview: The View class, which is extended again based on the Surfaceview view, is designed for the view of 3D game development; Surfaceview subclasses,OpenGL - specific.

(2) in 2D game development, can be divided into two kinds of game framework,View and surfaceview:

View and surfaceview differences:

• View : Must be in UI the main thread of the update screen for the passive update screen.

• Surfaceview : UI both threads and child threads are available. Redraw the screen in a newly started thread and actively update the screen.

2. updating the screen in the main thread of the UI may cause problems, such as when you update the screen for too long, then your main UI thread will be blocked by the function you are drawing. Then you will not be able to respond to keystrokes, touch screens and other messages. when using surfaceview because it is updating the screen in a new thread, it does not block your UI main thread. But this also brings up another problem, that is, event synchronization, which involves thread synchronization.

Therefore, based on the above, according to the characteristics of the game, generally divided into two categories.  

(1 ") passively update the screen. such as chess, the use of view just fine. Because the screen update is dependent on  , ONTOUCH  to update, you can use   directly; invalidate touch and the next touch It takes longer and has no impact.

(2) active update. Like a man running all the time. This requires a separate thread to redraw the human state continuously, avoiding blocking the main UI thread. So obviously the view is not suitable, need Surfaceview to control

Android Advanced Notes 05:view, Surfaceview and glsurfaceview relationships and differences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.