最近在做宠物连连看在真机上运行时。下面总是提示,点击事件触发不了,网上有回答说是因为不能再真机上运行,让后我就用AVD试了运行完全可以,所有功能都可以实现。
你的相关代码呢,光看日志也不知道你说什么。
你能把代码贴出来吗?
// 触碰游戏区域的处理方法
private void gameViewTouchDown(MotionEvent event) //①
{
// 获取GameServiceImpl中的Piece[][]数组
Piece[][] pieces = gameService.getPieces();
// 获取用户点击的x座标
float touchX = event.getRawX();
// 获取用户点击的y座标
float touchY = event.getRawY();
// 根据用户触碰的座标得到对应的Piece对象
Piece currentPiece = gameService.findPiece(touchX, touchY); //②
// 如果没有选中任何Piece对象(即鼠标点击的地方没有图片), 不再往下执行
if (currentPiece == null)
return;
// 将gameView中的选中方块设为当前方块
this.gameView.setSelectedPiece(currentPiece);
// 表示之前没有选中任何一个Piece
if (this.selected == null)
{
// 将当前方块设为已选中的方块, 重新将GamePanel绘制, 并不再往下执行
this.selected = currentPiece;
this.gameView.postInvalidate();
return;
}
// 表示之前已经选择了一个
if (this.selected != null)
{
// 在这里就要对currentPiece和prePiece进行判断并进行连接
LinkInfo linkInfo = this.gameService.link(this.selected,
currentPiece); //③
// 两个Piece不可连, linkInfo为null
if (linkInfo == null)
{
// 如果连接不成功, 将当前方块设为选中方块
this.selected = currentPiece;
this.gameView.postInvalidate();
}
else
{
// 处理成功连接
handleSuccessLink(linkInfo, this.selected
, currentPiece, pieces);
}
}
}
// 触碰游戏区域的处理方法
private void gameViewTouchUp(MotionEvent e)
{
this.gameView.postInvalidate();
}
// 以gameTime作为剩余时间开始或恢复游戏
private void startGame(int gameTime)
{
// 如果之前的timer还未取消,取消timer
if (this.timer != null)
{
stopTimer();
}
// 重新设置游戏时间
this.gameTime = gameTime;
// 如果游戏剩余时间与总游戏时间相等,即为重新开始新游戏
if(gameTime == GameConf.DEFAULT_TIME)
{
// 开始新的游戏游戏
gameView.startGame();
}
isPlaying = true;
this.timer = new Timer();
// 启动计时器 , 每隔1秒发送一次消息
this.timer.schedule(new TimerTask()
{
public void run()
{
handler.sendEmptyMessage(0x123);
}
}, 0, 1000);
// 将选中方块设为null。
this.selected = null;
}