Create a Growing Sprite?

All your problems with Audio, Video and Images.

Create a Growing Sprite?

Postby adqazwsx » Sun Jul 25, 2010 8:02 pm

What is the easiest way to create a sprite that grows over time. The sprite is contained on a SurfaceView and will be used for a game. My current implementation is to change the size of mPositionRectangle to be the desired mWidth and mHeight.

I currently use the following to grow the bitmap:
Code: Select all
    public void update(long deltaTime) {
       //TODO FIX
       double pixelsThisTick = mGrowthPerSecond * ((double) deltaTime) / MILLI_IN_SECOND;
       mWidth += pixelsThisTick;
       mHeight += pixelsThisTick;
       mPosition.xPos -= pixelsThisTick / 2;
       mPosition.yPos -= pixelsThisTick / 2;
       if(mWidth >= mMaxSize) mIsGrowing = false;


And this to handle the drawing:
Code: Select all
    public void draw(Canvas c){
       c.drawBitmap(mBitmap, mDrawableRectangle, mPositionRectangle, null);

This all works on the emulator, but does not work on the phone for some reason. On the phone the width of the sprites doesn't change.

Is there a better way to do this? I was considering using an animated sprite, but I need an implementation which is independent of screen size. Thanks for the help.
Posts: 8
Joined: Thu Jul 08, 2010 12:44 am


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 2 guests