cocos2d-x 3.x 触摸事件
HelloWorldScene.h
bool touchBegan(cocos2d::Touch*touch, cocos2d::Event*event);//触摸开始,返回bool类型
void touchMoved(cocos2d::Touch*touch, cocos2d::Event*event);
void touchEnded(cocos2d::Touch*touch, cocos2d::Event*event);
void touchCancelled(cocos2d::Touch*touch, cocos2d::Event*event);
HelloWorldScene.cpp
EventListenerTouchOneByOne*listener=EventListenerTouchOneByOne::create();
listener->onTouchBegan=CC_CALLBACK_2(HelloWorld::touchBegan,this);//触摸开始,必须添加,不使用也要添加,否则运行不通过
listener->onTouchMoved=CC_CALLBACK_2(HelloWorld::touchMoved,this);//触摸移动
listener->onTouchEnded=CC_CALLBACK_2(HelloWorld::touchEnded,this);//触摸中断,一般是系统层级的消息,如来电话,触摸事件就会被打断
listener->onTouchCancelled=CC_CALLBACK_2(HelloWorld::touchCancelled,this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener,this); bool HelloWorld::touchBegan(Touch*touch, Event*event){
Vec2 pos=touch->getLocation();
log("touchBegan x:%f,y:%f",pos.x,pos.y);
return true;//返回false时,触摸移动、触摸结束不会触发
} void HelloWorld::touchMoved(Touch*touch, Event*event){
Vec2 pos=touch->getLocation();
log("touchMoved x:%f,y:%f",pos.x,pos.y);
} void HelloWorld::touchEnded(Touch*touch, Event*event){
Vec2 pos=touch->getLocation();
log("touchEnded x:%f,y:%f",pos.x,pos.y);
} void HelloWorld::touchCancelled(Touch*touch, Event*event){
Vec2 pos=touch->getLocation();
log("touchCancelled x:%f,y:%f",pos.x,pos.y);
}
cocos2d-x 3.x 触摸事件的更多相关文章
- Cocos2d-android (06) 屏幕触摸事件及坐标转换
为屏幕添加触摸事件,将左上角坐标转换为左下角坐标 package com.arlen.cocos2d.touch01; import org.cocos2d.layers.CCLayer; impor ...
- cocos2d-x触摸事件优先级的探究与实践
如何让自定义Layer触发触摸事件? bool LayerXXX::init() { this->setTouchEnabled(true); CCTouchDispatcher* td = C ...
- cocos2d-x ios游戏开发初认识(八) 触摸事件与碰撞检測
玩过植物大战僵尸都知道,要在草坪里放一朵向日葵或者其他的植物仅仅需触摸那个植物将其拖入到想要摆放的位置,这事实上就是这节要写的触摸事件.还能够发现当我们的僵尸出来的时候,我们的小豌豆会发子弹攻击僵尸, ...
- Cocos2d-x示例:单点触摸事件
为了让大家掌握Cocos2d-x中的事件机制,以下我们以触摸事件为例.使用事件触发器实现单点触摸事件.该实比如图8-3所看到的,场景中有三个方块精灵,显示顺序如图8-3所看到的,拖拽它们能够移动它们. ...
- cocos2dx 3.x 触摸事件
单点触摸: bool onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent); void onTouchMoved(cocos2d:: ...
- cocos2d-x触摸事件优先级
CCTouchDispatcher是管理cocos2d-x中全部Touch事件派发的类, CCTouchDispatcher中包括了两个CCTouchHandler的列表, 分别存储Standa ...
- registerWithTouchDispatcher 注册单点触摸事件
Doc: If isTouchEnabled, this method is called onEnter. Override it to change the way CCLayer receive ...
- iOS 触摸事件与UIResponder(内容根据iOS编程编写)
触摸事件 因为 UIView 是 UIResponder 的子类,所以覆盖以下四个方法就可以处理四种不同的触摸事件: 1. 一根手指或多根手指触摸屏幕 - (void)touchesBegan:(N ...
- iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控
-- iOS事件全面解析 概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事 ...
随机推荐
- [ An Ac a Day ^_^ ] CodeForces 586C Gennady the Dentist 模拟
题意: n个小朋友去拔牙 每个小朋友在拔牙的时候会哭 哭声是vi分贝 距离门口vi远的小朋友听到了哭声会害怕 他们的勇气值p会减少d 如果勇气值p小于等于零 他们就会在门外哭并立即离开拔牙队列(回家找 ...
- Unity3D 回合制 网上源码 目前还在研究构思
我们已将回合制的战斗模式讲解得很清楚了.那么,如果在Unity3D游戏中实现一个回合制游戏呢?我们从最简单的一对一模式来设计回合制游戏的原型.我们可以游戏的状态划分为下面三种状态: 1. ...
- id和instancetype的异同
相同点: 都可以作为方法返回值类型 在initWithName:方法中是一样的,例如: - (id)initWithName:(NSString *)name; - (instancetype)ini ...
- NYOJ-1036 非洲小孩(贪心)
非洲小孩 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 家住非洲的小孩,都很黑.为什么呢?第一,他们地处热带,太阳辐射严重.第二,他们不经常洗澡.(常年缺水,怎么洗 ...
- css3动画 9步
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- c/c++ 浮点型处理
#include <stdio.h> #include <iostream> #include <string> #include <string.h> ...
- hibernate的批量更新、批量删除
hibernate的批处理API:session.createQuery(hql).executeUpdate(),如果有参数则在执行之前设置参数. 批量更新示例: @Test public void ...
- CentOS7 emacs安装
首先安装依赖库 依赖库: yum install gcc* yum install glib* yum install gtk* yum install ncurses* yum ...
- HTML中加载flash方法
首先贴上代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...
- Windows线程同步(下)
线程同步三:事件 CreateEvent:Creates or opens a named or unnamed event object. HANDLE WINAPI CreateEvent( _I ...