简体   繁体   中英

Synchronize Android Canvas Surfaceview

I am working on an android canvas game and have noticed a lagspike just as the main game form is being drawn. It started just after I started sprinkling synchronized(surfaceHandler) around different parts as an attempt to battle concurrent array modification. Did I over synchronize? What is the rule of thumb on when to synchronize and when not to, and when should visible data be modified?

Also is it possible that the spike is caused by something else? The draw method executes while this is happening, but no touch interaction is possible (most, if not all, of the touch method is synchronized).

Advice?

I think that as long as you are generated a canvas from the surface holder in one area, you shouldn't have to synchronize. This may or may not be causing the lagspike. If you are using surfaceHandler in multiple threads, you may want to condense all your drawing into one thread or you will need to keep the synchronize.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM