WEB开发网
开发学院手机开发iPhone 开发 iPhone方块游戏拖动手势源码共享 阅读

iPhone方块游戏拖动手势源码共享

 2010-08-22 00:49:00 来源:WEB开发网   
核心提示://连发次数加一return true;}}}return false;} //判断按了哪个虚拟键的小函数int GameStatePlay::touch_key(int x, int y){for(int i=0;i<11;i++){if(x>=BUTTON_RECT[i][0] && y>=BUT
//连发次数加一return true;}}}return false;} //判断按了哪个虚拟键的小函数int GameStatePlay::touch_key(int x, int y){for(int i=0;i<11;i++){if(x>=BUTTON_RECT[i][0] && y>=BUTTON_RECT[i][1] &&x<=BUTTON_RECT[i][2] && y<=BUTTON_RECT[i][3])return i;}return -1;} //开始触屏void GameStatePlay::TouchesBegan(){//设置初始坐标g_first_touch[0] = mApp->touch_x;g_first_touch[1] = mApp->touch_y;g_last_touch[0] = mApp->touch_x;g_last_touch[1] = mApp->touch_y;g_last_x = mApp->touch_x; //printf("TB:%f %f ", mApp->touch_x, mApp->touch_y); //主区域内准备检测手势,清空键盘状态表if(mApp->touch_y<=368 && mApp->touch_y>=46)memset(g_key, 0, sizeof(g_key)); //虚拟键盘区检测某个虚拟键被按下else{int k=touch_key(mApp->touch_x, mApp->touch_y);if(k!=-1){g_key[k][0]=KEY_DOWN;g_key[k][1]=0;}elsememset(g_key, 0, sizeof(g_key));}} //拖动及下扫手势void GameStatePlay::TouchesMoved(){//非主区域内,不检测手势,不处理move事件if(g_first_touch[1]>368 || g_first_touch[1]<46)return; //处理手势float dx, dx_drag, dy; dx = mApp->touch_x - g_last_touch[0];dx_drag = mApp->touch_x - g_last_x;dy = mApp->touch_y - g_last_touch[1]; g_last_touch[0]=mApp->touch_x;g_last_touch[1]=mApp->touch_y; //printf("TM:%f,%f ",g_last_touch[0], g_last_touch[1]); //水平拖动if(dy<=15){//距离上次拖动,又拖动了16个像素以上,模拟按了一下右移键if(dx_drag>15){//printf("PUT A RIGHT KEY dx2=%f ", dx_drag);g_key[ELSKEY_RIGHT][0]=KEY_PRESSED;g_key[ELSKEY_RIGHT][1]=0;g_last_x = mApp->touch_x;}//左移键盘if(dx_drag<-15){//printf("PUT A LEFT KEY dx2=%f ", dx_drag);g_key

[ELSKEY_LEFT][0]=KEY_PRESSED;g_key[ELSKEY_LEFT][1]=0;g_last_x = mApp->touch_x;} }else{//快速下扫事件,模拟按了一下DROP键if(dx<=5 && g_key[ELSKEY_DROP][1]==0){//printf("PUT A DROP KEY ");g_key[ELSKEY_DROP][0]=KEY_PRESSED;g_key[ELSKEY_DROP][1]=0;}g_last_x = mApp->touch_x;}} //旋转检测及松开屏幕的清理...void

Tags:iPhone 方块 游戏

编辑录入:coldstar [复制链接] [打 印]
赞助商链接