; //取得屏幕高度
Dice_x =(int)screen_width/2 - (int)dice.avgWidth/2; //计算骰子的X位置
Dice_y =(int)screen_height/3 - (int)dice.diceHeight/2; //计算骰子的Y位置
// Dice_x = 300;
// Dice_y =200;
System.out.println("screen_width=" + screen_width + ", screen_height=" + screen_height + ", Dice_x=" + Dice_x + ", Dice_y=" + Dice_y);
flag = true; //给flag设置初始值
th.start(); //启动线程
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
public void run(){
while(flag){
if(isRun){ //用判断语句控制是否进入骰子的投掷过程
for(i = 1; i <= 10; i++){ //随机取骰子值10次,完成投掷,建立此循环的目的是为了让线程持续执行,让投掷可控,
canvas = holder.lockCanvas(); //取得surfaceView的canvas
dice.playDice(canvas, Dice_x, Dice_y); //随机投掷骰子
if(canvas != null){
holder.unlockCanvasAndPost(canvas); //释放holder的画布
}
}
isRun = false;
}
}
try{
Thread.sleep(sleepSpan);
}catch(Exception e){
e.printStackTrace();
}
}
}