开发者

Whats the easiest way to animate 2D graphics on a surfaceview?

开发者 https://www.devze.com 2023-01-22 12:07 出处:网络
Currently I have a cartoon character that takes up almost the full screen of a surfaceview, and my little app is only to animate this 2D character during ontouch event at different coordinates.

Currently I have a cartoon character that takes up almost the full screen of a surfaceview, and my little app is only to animate this 2D character during ontouch event at different coordinates.

What I am doing now is to redraw the whole character every single time, and this way I need to have a specific graphic for every single frame.

I am just wondering if its better to split the character into different parts, e.g. heads, hands, legs, and wh开发者_运维百科enever a ontouch event happens, I only need to re-draw the specific part?

What do you think the pros and cons would be? Is it less CPU intensive?


This really comes down to how your images are set up. Having a single image taking up the whole screen means that every frame has to redraw the whole screen, something which an android device should be capable of doing. If you break your character into different parts it may look as if you only have to redraw a small part of the screen but if you just redraw one part around then it will still be in its old position unless you draw over it meaning you may have to do a full redraw anyway. Sometimes you can be clever and work out what areas of the screen need to be redrawn and then only redraw those but this can get very complicated. Another think worth thinking about is memory usage though, if you have a large number of full screen images in memory some phones may not have enough available memory and may crash. By breaking the image up into small parts you should reduce the chance of this.

0

精彩评论

暂无评论...
验证码 换一张
取 消