I'm trying to create a puzzle game, and I would like to learn about alternative ways to create puzzles without using a mask. I currently have puzzle pieces, taking the full image, breaking this image into four parts (say, a 2x2 puzzle), and then saving and applying a mask to each part. It looks as follows
// create standard puzzle pieces arryPieceEndPos = new int[mCols][mRows]; arryPieceImg = new Bitmap[mCols * mRows]; arryIsPieceLocked = new boolean[mCols * mRows]; int pos = 0; for (int c = 0; c < mCols; c++) { for (int r = 0; r < mRows; r++) { arryPieceImg[pos] = Bitmap.createBitmap(mBitmap, c * mPieceWidth, r * mPieceHeight, mPieceWidth, mPieceHeight); arryIsPieceLocked[pos] = false; arryPieceEndPos[c][r] = pos; pos++; } }
Then I use a helper method to apply a mask to each part
private Bitmap maskMethod(Bitmap bmpOriginal, Bitmap bmpMask) { // adjust mask bitmap if size is not the size of the puzzle piece if (bmpMask.getHeight() != mPieceHeight || bmpMask.getWidth() != mPieceWidth) { Log.e("TEST", "Resize Error :: H (mask): " + bmpMask.getHeight() + " // W (mask): " + bmpMask.getWidth()); Log.d("TEST", "Resize Error :: H (norm): " + mPieceHeight + " // W (norm): " + mPieceWidth); } Canvas canvas = new Canvas(); Bitmap combine = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888); canvas.setBitmap(combine); Paint paint = new Paint(); paint.setFilterBitmap(false); canvas.drawBitmap(bmpOriginal, 0, 0, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); canvas.drawBitmap(bmpMask, 0, 0, paint); paint.setXfermode(null); return combine; }
I saw this post> http://java.dzone.com/news/connect-pictures-android for connecting parts together, however this does not apply to generating parts programmatically without masks. Can someone provide some code examples on how to do this? The only key I have is that I have to use Path, however I'm still not sure how to do this. Thanks in advance!
source share