Hi all, interesting thread, here's my tuppenceworth.

My first attempt at a simple game took the same approach, things
looked favourable when I first threw a few dozen sprites onto the
canvas along with some simple game logic to try and get a handle on
fps and timing. I was getting around 40-45fps which I was happy with,
as my goal was around 30fps for the final game. I then added matrix
transformations to the sprites (scaling and/or rotating) and bang!
20-25fps... I fiddled some more for a while then gave up. I guessed
that without GL hardware acceleration, bitmap transforms just take way
too long. The only solution that I could come up with, was to cache a
whole load of transformed bitmaps prior to game start up, and draw/
swap these 'pre transformed' sprites directly to the canvas without
the use of matrix/rotate etc...

GL is probably the way to go, and biting the bullet might be the only
solution. It's a pity google don't provide a basic example of a 2d GL
game with their SDK, if they did, they might end up with a few more
decent games on the market.


On Jan 20, 7:05 am, Kevin Duffey <andjar...@gmail.com> wrote:
> Was just watching the video from back in May by Chris Pruett. He had a
> performance slide comparing canvas to opengl and as he noted there, canvas
> is much slower. I am sure you know this, but getting 30fps on a Canvas with
> more than a dozen or so sprites might be difficult when you factor in game
> logic, collision detections, etc. I didn't realize you were running this on
> the emulator as well. For sure you'll see much faster fps on a real device.
>
> On Tue, Jan 19, 2010 at 10:55 PM, Dan Sherman <impact...@gmail.com> wrote:
> > > I run my app on emulator, and currently have
> > > not tested it on real device.
>
> > The emulator is not, in any way, going to run the same speed as a real
> > device.
>
> > Run it on a real device and see what FPS you get.  Or if you want, publish
> > an APK and someone here will run it I'm sure (I'll do it =P)
>
> > - Dan
>
> > On Wed, Jan 20, 2010 at 1:44 AM, Andre <andranik.abra...@gmail.com> wrote:
>
> >> Hi,
>
> >> Yesterday, I've changed my code, to work with the matrix more
> >> effectively...
>
> >> My GameEntity class now looks like this:
>
> >> ----------GAME ENTITY----------
>
> >> public class GameEntity {
> >>        public Bitmap mBitmap;
> >>        private Rect mBounds;
> >>        private Matrix mMatrix;
> >>        public int mWidth;
> >>        public int mHeight;
> >>        public boolean mAlive;
> >>        public float mX, mY;
> >>        public float mVelocityX, mVelocityY;
> >>        public float mMoveAngle, mFaceAngle;
> >>        public float mRotationVelocity;
>
> >>        public GameEntity(Bitmap bitmap) {
> >>                mBitmap = bitmap;
> >>                mBounds = new Rect();
> >>                mMatrix = new Matrix();
> >>                mWidth = bitmap.getWidth();
> >>                mHeight = bitmap.getHeight();
> >>                mAlive = false;
> >>                mX = 0.0f;
> >>                mY = 0.0f;
> >>                mVelocityX = 0.0f;
> >>                mVelocityY = 0.0f;
> >>                mMoveAngle = 0.0f;
> >>                mFaceAngle = 0.0f;
> >>                mRotationVelocity = 0.0f;
> >>        }
>
> >>        public void draw(Canvas canvas, float angle) {
> >>                Matrix m = mMatrix;
> >>                m.reset();
> >>                m.postTranslate(mX - mWidth / 2, mY - mHeight / 2);
> >>                m.postRotate(angle, mX, mY);
> >>                canvas.drawBitmap(mBitmap, m, null);
> >>        }
>
> >>         public Rect getBounds() {
> >>                mBounds.left = (int)(mX - mWidth / 2);
> >>                mBounds.top = (int)(mY - mHeight / 2);
> >>                mBounds.right = (int)(mX + mWidth / 2);
> >>                mBounds.bottom = (int)(mY + mHeight / 2);
> >>                return mBounds;
> >>        }
> >> }
>
> >> And "draw" methods in GameView class:
>
> >> ----------GAME VIEW----------
>
> >> private void drawSpaceship(Canvas canvas) {
> >>         mSpaceship.draw(canvas, mSpaceship.mFaceAngle);
> >> }
>
> >> private void drawAsteroids(Canvas canvas) {
> >>        GameEntity[] asteroids = mAsteroids;
> >>        GameEntity asteroid;
> >>        for(int i = 0; i < MAX_ASTEROIDS; i++) {
> >>                asteroid = asteroids[i];
> >>                 if(asteroid.mAlive) {
> >>                        asteroid.draw(canvas, asteroid.mMoveAngle);
> >>                 }
> >>        }
> >> }
>
> >> private void drawBullets(Canvas canvas) {
> >>        GameEntity[] bullets = mBullets;
> >>         GameEntity bullet;
> >>        for(int i = 0; i < MAX_BULLETS; i++) {
> >>                bullet = bullets[i];
> >>                if(bullet.mAlive) {
> >>                        bullet.draw(canvas, bullet.mMoveAngle + 90);
> >>                }
> >>        }
> >> }
>
> >> This gives me an extra 4-5 FPS, and now I have ~25 FPS.
> >> It worth to mention, that I run my app on emulator, and currently have
> >> not tested it on real device.
>
> >> I decide to go little further with testing and commented out
> >> m.postTranslate() method call, and got +4 FPS, after that I commented
> >> out m.postRotate(), and got +12-15 FPS, it seems that rotation (with
> >> pivot points) is very costly...
>
> >> Best Regards, Andre
>
> >> --
> >> 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<android-developers%2bunsubscr...@googlegroups.com>
> >> For more options, visit this group at
> >>http://groups.google.com/group/android-developers?hl=en
>
> > --
> > 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<android-developers%2bunsubscr...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
>
-- 
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

Reply via email to