The little stuff definitely adds up and helps but when talking about such a small number of objects, I don't think it will double his FPS to fix.
First of all, thanks Andre for actually posting your code so that we have some context to work with and I'm also glad to hear that you've read my dev journal :) Upon first glance, I'm thinking that it's the transforms that are costing you so much. Can you try this for me? Create a field Matrix that you will reuse for every entity/object draw. At the beginning of your draw method, set the Canvas's matrix to that one. This will stop all of the Matrix allocating that you're ending up with. Every time you call Canvas.setMatrix(null), it nulls the matrix out, but then when you use a matrix function like Canvas.rotate(), it will create a new Matrix again, so you're instantiating lots of objects within your draw call and that's the first thing you'll want to stop doing. Now, instead of calling Canvas.setMatrix(null), you can just call myMatrix.loadIdentity(). That will reset the matrix and will make it so that anything you've done with it before that call is gone. I load up a default Paint() to use for bitmap draws, though after looking at the Canvas source, I don't know if it matters because it passes a 0 into the native method and I didn't look any further into the source. If you want to be sure that you're not antialiasing or anything like that, use a default Paint() instance for drawing bitmaps and do not set antialiasing or anything like that on it. That will cost you. Also, the surface your drawing on is opaque, not transparent, right? It'll cost more to draw onto a transparent surface. I'm also wondering if something screwy is going on, like somehow the bitmaps you're drawing are much bigger than you think they are. I'd throw some logging in of Bitmap dimensions when they are loaded so you know exactly how many pixels are being copied. Perhaps you'll find something awry there. If you're still having problems, I recommend isolating calls to see if any one thing is hurting you more, then investigating it. It's hard to test everything you've got all at once for performance. On Jan 18, 8:07 am, skink <psk...@gmail.com> wrote: > On Jan 18, 2:49 pm, Andre <andranik.abra...@gmail.com> wrote: > > > > > > > Let me clarify... > > > Lets look at two methods: > > - updateAsteroidsPhysics() > > - drawAsteroids(Canvas canvas) > > They both use getters instead of members, and asteroids[i] instead of > > asteroid variable, the only difference between them, that drawAsteroids > > (Canvas canvas) is also use canvas calls, and I think this is most > > heavy part, becouse: > > > updateSpaceshipPhysics(); > > updateAsteroidsPhysics(); > > updateBulletsPhysics(); > > checkForCollisions(); > > > takes ~1-5ms to perform, and: > > > drawSpaceship(canvas); > > drawAsteroids(canvas); > > drawBullets(canvas); > > > takes ~25ms to perform (and even more, if I increase number of > > asteroids or start to fire bullets) > > yes, i know, thats why you should optimize your draw*(Canvas) methods. > > now, after changes, do you see any changes in FPS? > > pskink
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en