Android 黑白子游戏开发实例
2010-03-31 05:20:00 来源:WEB开发网hilite.setColor(getResources().getColor(R.color.puzzle_hint_0));
selected.setColor(getResources().getColor(R.color.puzzle_selected));
moveFont=new Paint();
String familyName="Arial";
Typeface font=Typeface.create(familyName,Typeface.BOLD);
moveFont.setColor(Color.RED);
moveFont.setTypeface(font);
moveFont.setTextSize(22);
}
@Override
protected void onSizeChanged(int w,int h,int oldw,int oldh){
initImg(w,h);
Log.d(TAG,"onSizeChanged: width "+gridW+", height "+gridH);
super.onSizeChanged(w,h,oldw,oldh);
}
/**
* 初始化屏幕大小,图片
*
* @param w
* @param h
*/
private void initImg(int w,int h){
screenWidth=(float)w;
screenHeight=(float)h;
gridW=(float)(screenWidth/Game.level);
gridH=(float)((screenHeight-40)/Game.level); // 当作默认高比宽多
setNewBitmap();
}
// 设置新位图.
private void setNewBitmap(){
// 设置纵横比.
float w=gridW/bitmap2.getWidth();
float h=gridH/bitmap2.getHeight();
Matrix matrix=new Matrix();
matrix.postScale(w*0.88f,h*0.88f);
// 设置新的大小的位图.
dstbmp1=Bitmap.createBitmap(bitmap1,0,0,bitmap1.getWidth(),bitmap1.getHeight(),
matrix,true);
dstbmp2=Bitmap.createBitmap(bitmap2,0,0,bitmap2.getWidth(),bitmap2.getHeight(),
matrix,true);
}
@Override
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
// 画背景
canvas.drawRect(0,0,screenWidth,screenHeight,background);
// 画网格
for(int i=0;i<=Game.level;i++){
canvas.drawLine(0,i*gridH,screenWidth,i*gridH,hilite);
canvas.drawLine(0,i*gridH+1,screenWidth,i*gridH+1,hilite);
更多精彩
赞助商链接