14.06.2011

surface, doDraw and update physics

posted by Karsten

/* * Surfaces and drawing */ public void setSurfaceSize(int width, int height) { synchronized (mSurfaceHolder) { mCanvasWidth = width; mCanvasHeight = height; // don't forget to resize the background image mBackgroundImage = Bitmap.createScaledBitmap(mBackgroundImage, width, height, true); } } protected void doDraw(Canvas canvas) { if(canvas == null) return; if(mBackgroundImage != null) canvas.drawBitmap(mBackgroundImage, 0, 0, null); canvas.drawBitmap(mBall, mBallX, mBallY, null); } protected void updatePhysics() { long now = System.currentTimeMillis(); float elapsed = (now - mLastTime) / 1000.0f; mBallX += elapsed * mBallDX; mBallY += elapsed * mBallDY; if((mBallX = mCanvasWidth - mBall.getWidth() & mBallDX > 0) ) { mBallDX = -mBallDX; updateScore(1); } if(mBallY = mCanvasHeight - mBall.getHeight()) setState(GameThread.STATE_WIN); mLastTime = now; }

Share

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment