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
- ››iphone图片拉伸的几种方法
- ››iphone正则表达式的简单使用
- ››iPhone开发Unresolved Symbols CAKeyframeAnimati...
- ››IPhone开发-“此证书是由未知颁发机构签名”解决方...
- ››IPhone开发-整合私钥和证书,生成.p12文件
- ››iPhone应用开发-UIPickerView选取器详解
- ››iphone 获取屏幕的宽度和高度
- ››iPhone读取工程包中的二进制文件
- ››iPhone新手机 不挂YouTube APP
- ››iPhone 获取指定格式的时间和日期
- ››iPhone版PPS走进生活 观赏体验媲美PC版
- ››iPhone两种不同的应用程序:两种方法的哲学思想
更多精彩
赞助商链接