performance - Performant 2D rendering with Android's Canvas API -
over last month, i've taken dive trying hand @ simple 2d side scroller using android's default canvas apis.
in short, question boils down "is canvas api performant enough pull 60fps simple side scroller multi-layer, parallaxing background?".
now hear me out, because i've tried ton of different approaches, , far i've come empty handed on how squeeze more efficiency out of i've attempted.
first, address easy problems:
- i'm not allocating in game loop
- the surface hardware accelerated
- bitmaps being loaded prior starting game, , drawn without scaling.
- i don't believe i'm doing significant aside bitmap drawing in game loop (mostly updating position variables , getting time)
the problems started, may have guessed, parallaxing bg. 7 layers in total, though i've been experimenting few 3 while still unable maintain 60fps. i'm clipping parts overlapping minimize overdraw, guess i'm still drawing ~2-3x overdraw, summed up.
as game runs, start out @ ~ 60fps, 30/40 seconds in, fps drops 20. time random, , seems state of phone, rather result of in code (force killing app & restarting causes new app start @ ~20fps, letting phone sit while results in higher fps). guess here thermal throttling on cpu...
now i'm testing on 5x, , naively thought these issues might disappear on faster device (6p). of course, due larger screen, problems got worse, ran @ ~15fps continuously.
a co-worker had suggested loading in small bitmaps , stretching them on draw, instead of scaling bitmaps on load size appear on screen. implementing making each bitmap 1/3rd size, , using canvas.drawbitmap(bitmap, srcrect, destrect, paint) method compensate size , scale yielded worse performance overall (though i'm sure helped memory footprint). haven't tried drawmesh method, imagined wouldn't more performant plain old drawbitmap.
in attempt, gave array of imageviews shot, thinking android view class might doing magic wasn't, after hour of fiddling it, didn't more promising.
lastly, gpu profiling on device remains far beneath green line, indicating 60fps, screen doesn't seem reflect that. not sure what's going on there.
should bite bullet , switch on opengl? thought canvas task of side-scroller parallaxing background, i'm either doin' wrong™, or using wrong tool job, seems.
any or suggestions sincerely appreciated, , apologies long-winded post.
Comments
Post a Comment