转自:http://www.cnblogs.com/fjut/archive/2012/04/28/2475693.html

//ccTouchBegan必须实现,否则会报错
bool PicScan::ccTouchBegan(CCTouch* pTouch, CCEvent* event)
{
return true;
} void PicScan::ccTouchMoved(CCTouch *touch, CCEvent *event)
{
//获得触摸点初始坐标
CCPoint beginLoc = touch->locationInView(touch->view());
beginLoc = CCDirector::sharedDirector()->convertToGL(beginLoc); //判断鼠标拖拉的区域是否在图片上
if(CCRect::CCRectContainsPoint(lpSprite->boundingBox(), this->getParent()->convertTouchToNodeSpace(touch)) == true)
{
//固定图片在某个区域
if(lpSprite->getPosition().y > s.height/+)
{
lpSprite->setPosition(ccp(lpSprite->getPosition().x, s.height/+));
} if(lpSprite->getPosition().y < s.height/-)
{
lpSprite->setPosition(ccp(lpSprite->getPosition().x, s.height/-));
}
printf(" ccTouchMoved --------------\n"); //获得前一个触摸点坐标
CCPoint endLoc = touch->previousLocationInView(touch->view());
endLoc = CCDirector::sharedDirector()->convertToGL(endLoc); //计算偏移量
CCPoint offSet = ccpSub(beginLoc, endLoc);
Drag(offSet);
} } void PicScan::Drag(CCPoint offSet)
{
//计算精灵坐标加上移动偏移量、并设置精灵位置
CCPoint pos = ccpAdd(lpSprite->getPosition(), offSet);
lpSprite->setPosition(pos);
//.....<br>}

cocos2d-x 触摸偏移的更多相关文章

  1. cocos2d CCLayer 触摸相关

    要让一个  CCLayer 能够接受触摸输入  需要进行如下设置: [selfsetTouchEnabled:YES]; cocos2d-x提供了两种触摸事件处理机制, 分别是CCStandardTo ...

  2. cocos2d-x学习日志(10) --射击游戏(喵星战争)

    转载请标明:转载自[小枫栏目],博文链接:http://blog.csdn.net/rexuefengye/article/details/10553487 一.纵版射击游戏的特点 纵版射击游戏是一种 ...

  3. cocos2d-x 手势之简单实现

    转自:http://blog.sina.com.cn/s/blog_61ece099010187tl.html 手势之前也发过一篇,但是我感觉那个还不够轻巧. 而且大多数游戏里面不会有那么复杂的手势, ...

  4. HTCVive使用

    1.设备的安装与配置 https://wenku.baidu.com/view/fa172fd7482fb4daa48d4b44.html?from=search 2.接入SDK.实现简单示例场景.更 ...

  5. 关于Unity中的Input输入事件

    截获鼠标,键盘的消息 监听事件我们都是在Update里面监听的. Unity的虚拟轴打开:Edit-->Project Settings-->Input,打开的各个Name就是双引号里面要 ...

  6. 【Cocos2d入门教程六】Cocos2d-x事件篇之触摸

    Cocos游戏当中产生一个事件时,可以有多个对象在监听该事件,所以有优先级(Priority).优先级越高(Priority值越小),事件响应越靠前. 关系图: 新 事件分发机制:在2.x 版本事件处 ...

  7. cocos2d触摸事件处理机制(2.x和3.x变化)

    2.x的触摸事件的版本号 触摸事件处理有2种子.以下单点触摸的样本.(另一种多点触摸屏). 创建cocos2d 该项目. 1. 重写下面虚函数. bool ccTouchBegan(cocos2d:: ...

  8. Cocos2D v3.x中关于重叠触摸层优先级的问题

    在Cocos2D v2.x版本中可以通过以下方法设置本层的触摸优先级: [[CCDirector sharedDirector].touchDispatcher addTargetedDelegate ...

  9. [cocos2d] 谁摸了我一下----触摸事件处理

    1. 设置接受触摸事件,可在init方法里面写上 [self setTouchEnabled: YES]; 旧版为self.isTouchEnabled = YES; xcode会报Deprecati ...

随机推荐

  1. The document has been modified outside of Code Composer. Would you like to reload the file

    2013-06-20 10:03:32 烧写过程是合众达给出的文档 problem: I'm new to using Code Composer Studio 3.3 and am having a ...

  2. (转)linux 技巧:使用 screen 管理你的远程会话

    转自:http://www.ibm.com/developerworks/cn/linux/l-cn-screen/index.html 你是不是经常需要 SSH 或者 telent 远程登录到 Li ...

  3. The only legal comparisons are between two numbers, two strings, or two dates.

    The only legal comparisons are between two numbers, two strings, or two dates. Left  hand operand is ...

  4. UVa 753 (二分图最大匹配) A Plug for UNIX

    题意: 有n个插座,m个设备以及k种转化器(每种转化器视为有无限个). 转换器A->B可以将A类型的插头转化成B类型的插头,所以可以插在B类型的插座上. 求最少剩多少不匹配的设备. 分析: 抛开 ...

  5. BZOJ3155: Preprefix sum

    题解: 写过树状数组搞区间修改和区间求和的就可以秒出吧... 代码: #include<cstdio> #include<cstdlib> #include<cmath& ...

  6. vijos1049送给圣诞夜的礼品

    这题犯了两个sb错误,写下来,为以后做个警告 一.mul过程中将k作为了循环变量 二.看错了题…… 题目中说是数到k行,而我却以为数k遍…… 做矩阵乘法,只要记住一句话:置换一定可以写成矩阵的形式! ...

  7. vijos1194 Domino

    vijos上的题解: 1.因为每个格子不是被覆盖就是没被覆盖,状态只有0 1两种,m<=5,所以可以将每一列的状态压缩,看作一个二进制数.2.矩阵G表示从I状态到J状态的路径条数,自乘N次为长度 ...

  8. po 时不生效时, 不要用点方法

    Dot notation for message sending is not supported in lldb. Use bracket notation and cast the result ...

  9. GRIB格式转换心得(转自博客:http://windforestwing.blog.163.com/blog/static/19545412007103084743804/)

    1.wgrib的使用 在cmd命令行下键入wgrib后即可察看wgrib相关命令参数,简要介绍如下: l        Inventory/diagnostic–output selections 详 ...

  10. JQuery focus()

    跳转到登陆页面时可以使用focus方法 <input name="login_account"id="login_account"class=" ...