我创建了一个游戏,其中如果用户按下按钮,它将沿特定方向移动蛇。
而是当您按下按钮时,我要这样做,以便当手指悬停在按钮上时,蛇会移动。
所以我将方法从更改setOnTouchListener为setOnHoverListener
这是我的代码:
Button btnRight = (Button) findViewById(R.id.btnRight);
btnRight.setOnHoverListener(new OnHoverListener(){
public boolean onHover(View v, MotionEvent event) {
if(direction!=4)
direction = 6;
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
当手指在屏幕上按下并在按钮上拖动时,什么也没有发生。
当手指在按钮上拖动时,如何注册它?有没有简单的方法解决方案,还是我必须检测坐标等?
我有一个项目,我在C中创建几个动态的二维整数数组.
我试图通过创建mallocateArray函数来减少冗余代码.没有这个功能我可以让它工作.
问题是指针可能是一个麻烦,并且由于某种原因,当我尝试使用此方法时,我只是遇到了一个seg错误:
继承人我得到了什么:
void mallocateArray(int ***array, int *row, int *col){
//allocate storage for the array of ints:
*array = (int**)malloc(*row * sizeof(int *));
int i;
for (i = 0; i < *row; i++){
*array[i] = (int*)malloc(*col * sizeof(int));
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的数组定义方式:
int **matrix1,
int row = 2
int col = 3
mallocateArray(&matrix1, &row, &col);
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到一个段错误.所以目前我只是不使用该方法并处理冗余.我试过搞乱指针,解除引用等等,但我似乎无法弄明白.
我希望你们能帮助我.
下面是我的main方法中的代码示例:
result = (int**)malloc(row1 * sizeof(int *));
int i;
for (i = 0; i < row1; i++){
result[i] = (int*)malloc(col2 * sizeof(int));
}
Run Code Online (Sandbox Code Playgroud)