欢迎来到我的另外一篇android游戏开发教程,今天我会使用zgf开发框架实现虚拟按键,使用虚拟按键控制之前编写的动画,现在让我们开始吧。
一.实现虚拟按键
打开zgf api看到框架中有个package叫做com.zxx43.commen.key,打开它可以看到ImageButton和KeyUtil两个类,ImageButton是图形按钮,而KeyUtil是触摸点。建立虚拟按键类Key,在这个类中将会使用到上面这两个类的方法。Key类代码如下:
//图形按键对象
private ImageButton btnUp;
private ImageButton btnDown;
private ImageButton btnLeft;
private ImageButton btnRight;
//还没有按的图像
private Bitmap leftMap;
private Bitmap rightMap;
private Bitmap upMap;
private Bitmap downMap;
//按键按下的图像
private Bitmap leftClickMap;
private Bitmap rightClickMap;
private Bitmap upClickMap;
private Bitmap downClickMap;
//设置按键位置
int btnL=leftMap.getWidth();
int btnH=leftMap.getHeig