转载自 shahdza

http://cn.cocos2d-x.org/tutorial/show?id=1623

在2.x中处理事件需要用到委托代理(delegate),相信学过2.x的触摸事件的同学,都知道创建和移除的流程十分繁琐。而在3.x中由于加入了C++11的特性,而对事件的分发机制通过事件分发器Eventdispatcher 来进行统一的管理。


事件监听器主要有:

  • 触摸事件 : EventListenerTouchOneByOne、EventListenerTouchAllAtOnce

  • 鼠标响应事件 : EventListenerMouse

  • 键盘响应事件 : EventListenerKeyboard

  • 加速计事件 : EventListeneracceleration

  • 自定义事件 : EventListenerCustom

  • 物理碰撞事件 : EventListenerPhysicsContact

  • 游戏手柄事件 : EventListenerController

【事件分发器】

事件分发器Eventdispatcher,用于统一管理事件监听器的所有事件的分发。

1、_eventdispatcher

_eventdispatcher是Node的属性,通过Director::getInstance()->getEventdispatcher() 获得。

_eventdispatcher的工作由三部分组成:

(1)事件分发器 :Eventdispatcher。

(2)事件类型 :EventTouch,EventKeyboard 等。

(3)事件监听器 :EventListenerTouch,EventListenerKeyboard 等。

监听器实现了各种触发后的逻辑,在适当时候由事件分发器分发事件类型,然后调用相应类型的监听器。

2、添加/删除监听器

添加监听器:addEventListenerWithSceneGraPHPriority,addEventListenerWithFixedPriority。

删除监听器:removeEventListener,removeAllEventListeners。

3、主要函数

包含监听器的添加、删除、暂停、恢复,优先级的设置,手动分发事件等。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
class Eventdispatcher: public Ref
{
/**
*添加监听器
*-addEventListenerWithSceneGraPHPriority
*-addEventListenerWithFixedPriority
*-addCustomEventListener
*/
//使用场景图的优先级为指定事件添加一个监听.
//listener:指定要监听的事件.
//node:这个节点的绘制顺序是基于监听优先级.
//优先级:0
void addEventListenerWithSceneGraPHPriority(EventListener*listener,Node*node);
//使用一定的优先级为指定事件添加一个监听.
//listener:指定要监听的事件.
//fixedPriority:这个监听器的固定优先级.
//优先级:fixedPriority。(但是不能为0,因为他是场景图的基本优先级)
addEventListenerWithFixedPriority(EventListener*listener, int fixedPriority);
//用户自定义监听器
EventListenerCustom*addCustomEventListener( const std::string&eventName, std::function< (EventCustom*)>&callback);
/**
*删除监听器
*-removeEventListener
*-removeEventListenersForType
*-removeEventListenersForTarget
*-removeCustomEventListeners
*-removeAllEventListeners
*/
//删除指定监听器
removeEventListener(EventListener*listener);
//删除某类型对应的所有监听器
//EventListener::Type::
//单点触摸:TOUCH_ONE_BY_ONE
//多点触摸:TOUCH_ALL_AT_ONCE
//键盘:KEYBOARD
//鼠标:MOUSE
//加速计:acceleration
//自定义:CUSTOM
removeEventListenersForType(EventListener::TypelistenerType);
//删除绑定在节点target上的所有监听器
removeEventListenersForTarget(Node*target,monospace!important; font-size:1em!important; min-height:inherit!important; color:gray!important; background:none!important">bool recursive= false );
//删除名字为customEventName的所有自定义监听器
removeCustomEventListeners( std::string&customEventName);
//移除所有监听器
removeAllEventListeners();
/**
*暂停、恢复在节点target上的所有监听器
*-pauseEventListenersForTarget
*-resumeEventListenersForTarget
*/
pauseEventListenersForTarget(Node*target,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
resumeEventListenersForTarget(Node*target,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
/**
*其他
*-setPriority
*-setEnabled
*-dispatchEvent
*-dispatchCustomEvent
*/
//设置某监听器的优先级
setPriority(EventListener*listener,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">fixedPriority);
//启用事件分发器
setEnabled( isEnabled);
isEnabled() ;
//手动派发自定义事件
dispatchEvent(Event*event);
//给名字为eventName的自定义监听器,绑定用户数据
dispatchCustomEvent( *optionalUserData=nullptr);
}
//

4、关于事件监听器的优先权

通过 addEventListenerWithSceneGraPHPriority 添加的监听器,优先权为0。

通过 addEventListenerWithFixedPriority 添加的监听器,可以自定义优先权,但不能为0。

  • 优先级越低,越先响应事件。

  • 如果优先级相同,则上层的(z轴)先接收触摸事件。

5、使用步骤

(1)获取事件分发器 :dispatcher = Director::getInstance()->getEventdispatcher();

(2)创建监听器 :auto listener = EventListenerTouchOneByOne::create();

(3)绑定响应事件函数:listener->onTouchBegan = CC_CALLBACK_2(callback,this);

(4)将监听器添加到事件分发器dispatcher中:dispatcher->addEventListenerWithSceneGraPHPriority(Listener,this);

(5)编写回调响应函数:bool callback(Touch* touch,Event* event) { ... }

【触摸事件】

1、单点触摸:EventListenerTouchOneByOne

单点触摸监听器相关:

8
//
static EventListenerTouchOneByOne*create();
std::function< (Touch*,Event*)>onTouchBegan; //只有这个返回值为bool
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,Event*)>onTouchMoved;
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,Event*)>onTouchEnded;
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,Event*)>onTouchCancelled;
使用举例:
23
//获取事件分发器
autodispatcher=Director::getInstance()->getEventdispatcher();
//创建单点触摸监听器EventListenerTouchOneByOne
autotouchListener=EventListenerTouchOneByOne::create();
//单点触摸响应事件绑定
touchListener->onTouchBegan=CC_CALLBACK_2(HelloWorld::onTouchBegan,153)!important; background:none!important">this );
touchListener->onTouchMoved=CC_CALLBACK_2(HelloWorld::onTouchMoved,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
touchListener->onTouchEnded=CC_CALLBACK_2(HelloWorld::onTouchEnded,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
touchListener->onTouchCancelled=CC_CALLBACK_2(HelloWorld::onTouchCancelled,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
//在事件分发器中,添加触摸监听器,事件响应委托给this处理
dispatcher->addEventListenerWithSceneGraPHPriority(touchListener,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
//单点触摸事件响应函数
onTouchBegan(Touch*touch,Event*unused_event){cclOG( "began" ); return true ;}
onTouchMoved(Touch*touch,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"moved" );}
onTouchEnded(Touch*touch,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"ended" );}
onTouchCancelled(Touch*touch,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"cancelled" );}
2、多点触摸:EventListenerTouchAllAtOnce

多点触摸监听器相关:

8
EventListenerTouchAllAtOnce*create();
( std::vector<Touch*>&,Event*)>ontouchesBegan;
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,Event*)>ontouchesMoved;
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,Event*)>ontouchesEnded;
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,Event*)>ontouchesCancelled;
使用举例:
23
//创建多点触摸监听器EventListenerTouchAllAtOnce
autotouchesListener=EventListenerTouchAllAtOnce::create();
//多点触摸响应事件绑定
touchesListener->ontouchesBegan=CC_CALLBACK_2(HelloWorld::ontouchesBegan,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">touchesListener->ontouchesMoved=CC_CALLBACK_2(HelloWorld::ontouchesMoved,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">touchesListener->ontouchesEnded=CC_CALLBACK_2(HelloWorld::ontouchesEnded,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">touchesListener->ontouchesCancelled=CC_CALLBACK_2(HelloWorld::ontouchesCancelled,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">dispatcher->addEventListenerWithSceneGraPHPriority(touchesListener,0)!important; background:none!important">//多点触摸事件响应函数
ontouchesBegan( std::vector<Touch*>&touches,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);}
ontouchesMoved( ontouchesEnded( ontouchesCancelled( 【鼠标事件】

EventListenerMouse,主要用于监听鼠标的点击、松开、移动、滚轮的事件。

鼠标事件监听器相关:

8
EventListenerMouse*create();
(Event*event)>onMouseDown; //按下鼠标,单击鼠标
(Event*event)>onmouseup; //松开鼠标,按下的状态下松开
(Event*event)>onMouseMove; //移动鼠标,在屏幕中移动
(Event*event)>onMouseScroll; //滚动鼠标,滚动鼠标的滚轮
23
//创建鼠标事件监听器EventListenerMouse
EventListenerMouse*mouseListenter=EventListenerMouse::create();
//鼠标事件响应函数
mouseListenter->onMouseDown=CC_CALLBACK_1(HelloWorld::onMouseDown,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">mouseListenter->onmouseup=CC_CALLBACK_1(HelloWorld::onmouseup,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">mouseListenter->onMouseMove=CC_CALLBACK_1(HelloWorld::onMouseMove,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">mouseListenter->onMouseScroll=CC_CALLBACK_1(HelloWorld::onMouseScroll,0)!important; background:none!important">//添加鼠标事件监听器,事件响应处理委托给this
dispatcher->addEventListenerWithSceneGraPHPriority(mouseListenter,0)!important; background:none!important">//事件响应函数
onMouseDown(Event*event){cclOG( "Down" onmouseup(Event*event){cclOG( "UP" onMouseMove(Event*event){cclOG( "MOVE" onMouseScroll(Event*event){cclOG( "Scroll"

【键盘事件】

EventListenerKeyboard,主要用于监听键盘某个键的按下、松开的事件。

键盘事件监听器相关:

17
EventListenerKeyboard*create();
(EventKeyboard::KeyCode,Event*)>onKeypressed; //按下某键
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,Event*)>onkeyreleased; //松开某键
//键盘按键枚举类型EventKeyboard::KeyCode
//KeyCode的值对应的不是键盘的键值、也不是ASCII码,只是纯粹的枚举类型
//如:
//EventKeyboard::KeyCode::KEY_A
//EventKeyboard::KeyCode::KEY_1
//EventKeyboard::KeyCode::KEY_F1
//EventKeyboard::KeyCode::KEY_SPACE
//EventKeyboard::KeyCode::KEY_ALT
//EventKeyboard::KeyCode::KEY_SHIFT
27
//创建键盘按键事件监听器
EventListenerKeyboard*keyboardListener=EventListenerKeyboard::create();
//绑定事件响应函数
keyboardListener->onKeypressed=CC_CALLBACK_2(HelloWorld::onKeypressed,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">keyboardListener->onkeyreleased=CC_CALLBACK_2(HelloWorld::onkeyreleased,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">
//添加监听器
dispatcher->addEventListenerWithSceneGraPHPriority(keyboardListener,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
//事件响应函数
onKeypressed(EventKeyboard::KeyCodekeyCode,Event*event){
if (EventKeyboard::KeyCode::KEY_J==keyCode){
cclOG( "pressed:J" );
}
}
onkeyreleased(EventKeyboard::KeyCodekeyCode,Event*event){
(EventKeyboard::KeyCode::KEY_SPACE==keyCode){
"Released:SPACE" );
}
}
【加速计事件】

EventListeneracceleration,主要用于监听移动设备的所受重力方向感应事件。

重力感应来自移动设备的加速计,通常支持 (X,Y,Z) 三个方向的加速度感应,所以又称为三向加速计。在实际应用中,可以根据3个方向的力度大小来计算手机倾斜的角度或方向。

1、加速计信息类acceleration

该类中每个方向的加速度,大小都为一个重力加速度大小。

6
//加速计信息
acceleration
{
double x; y; z;
};
2、开启加速计感应

在使用加速计事件监听器之前,需要先启用此硬件设备:

1
Device::setAccelerometerEnabled( );

3、加速计监听器相关

5
EventListeneracceleration*create( (acceleration*,Event*)>&callback);
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,Event*)>onaccelerationEvent;
4、使用举例
41
//标签:显示加速计信息
label=Label::createWithTTF( "noused" , "MarkerFelt.ttf" ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,12);
label->setPosition(visibleSize/2);
->addChild(label);
//小球:可视化加速计
ball=Sprite::create( "ball.png" ball->setPosition(visibleSize/2);
->addChild(ball);
//获取事件分发器
autodispatcher=Director::getInstance()->getEventdispatcher();
//需要开启移动设备的加速计
);
//创建加速计事件监听器
autoaccelerationListener=EventListeneracceleration::create(CC_CALLBACK_2(HelloWorld::onaccelerationEvent,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">));
//添加加速计监听器
dispatcher->addEventListenerWithSceneGraPHPriority(accelerationListener,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">
//事件响应函数
HelloWorld::onaccelerationEvent(acceleration*acceleration,Event*event)
{
char s[100];
sprintf (s,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"X:%f;Y:%f;Z:%f;" ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,acceleration->x,acceleration->y,acceleration->z);
label->setString(s);
//改变小球ball的位置
float x=ball->getPositionX()+acceleration->x*10;
y=ball->getPositionY()+acceleration->y*10;
Vec2pos=Vec2(x,y);
pos.clamp(ball->getContentSize()/2,Vec2(288,512)-ball->getContentSize()/2);
ball->setPosition(pos); //设置位置
}
5、实际效果

在电脑上看不出效果,需要移植到手机上,才能看到加速计的效果。

【自定义事件】

以上是系统自带的事件类型,事件由系统内部自动触发,如 触摸屏幕,键盘响应等。

EventListenerCustom 自定义事件,它不是由系统自动触发,而是人为的干涉。

1、创建自定义监听器

5
//eventName:监听器名字
//callback:监听器函数
EventListenerCustom*create( (EventCustom*)>&callback);
2、分发自定义事件

自定义的事件监听器,需要通过手动的方式,将事件分发出去。

通过 EventCustom(string eventName); 来获取自定义监听器。

通过 dispatcher->dispatchEvent(&event); 来手动将事件分发出去。

4
EventCustomevent( "your_event_type" );
dispatcher->dispatchEvent(&event);
3、使用举例
23
//创建自定义事件监听器
//监听器名字:"custom_event"
//事件响应函数:HelloWorld::onCustomEvent
autocustomListener=EventListenerCustom::create( "custom_event" ));
//添加自定义事件监听器,优先权为1
dispatcher->addEventListenerWithFixedPriority(customListener,1);
//手动分发监听器的事件,通过dispatchEvent
EventCustomevent=EventCustom( );
dispatcher->dispatchEvent(&event);
HelloWorld::onCustomEvent(EventCustom*event)
{
"onCustomEvent" );
}
4、说明
  • 每个自定义的事件监听器,都有一个监听器名字eventName。

  • 需要手动通过 dispatcher->dispatchEvent(&event); 来手动将事件分发出去。

  • 可以通过 dispatcher->dispatchCustomEvent(,); 来给自定义事件监听器绑定一个用户数据。

来源网址:http://www.jb51.cc/article/p-zwifwspg-wx.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


如何使用CCRenderTexture创建动态纹理 Cocos2d-x 2 1 4
    本文实践自 RayWenderlich、Ali Hafizji 的文章《How To Create Dynamic Textures with CCRenderTexture in Cocos2D 2.X》,文中使用Cocos2D,我在这里使用Cocos2D-x 2.1.4进行学习和移植。在这篇文章,将会学习到如何创建实时纹理、如何用Gimp创建无缝拼接纹
Cocos-code-ide使用入门学习
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@163.com微信公众号:HopToad 欢迎转载,转载标注出处:http://blog.csdn.netotbaron/article/details/424343991.  软件准备 下载地址:http://cn.cocos2d-x.org/download 2.  简介2.1         引用C
Cocos2D-x-3.0 编译(Win7)
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从Cocos2D-x官网上下载,进入网页http://www.cocos2d-x.org/download,点击Cocos2d-x以下的Download  v3.0,保存到自定义的文件夹2:从python官网上下载。进入网页https://www.python.org/downloads/,我当前下载的是3.4.0(当前最新
quick-cocos2d-x实例之挑战记忆极限设计文档
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《最强大脑》娱乐节目。将2048改造成一款挑战玩家对数字记忆的小游戏。邮箱:appdevzw@163.com微信公众号:HopToadAPK下载地址:http://download.csdn.net/detailotbaron/8446223源码下载地址:http://download.csdn.net/
Cocos2d-x 3 X CMake MinGW版本编译运行
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试以QtCreatorIDE来进行CMake构建。Cocos2d-x3.X地址:https://github.com/cocos2d/cocos2d-x1.打开QtCreator,菜单栏→"打开文件或项目...",打开cocos2d-x目录下的CMakeLists.txt文件;2.弹出CMake向导,如下图所示:设置
vs 2013 编译cocos2d-x-3.9
 下载地址:链接:https://pan.baidu.com/s/1IkQsMU6NoERAAQLcCUMcXQ提取码:p1pb下载完成后,解压进入build目录使用vs2013打开工程设置平台工具集,打开设置界面设置: 点击开始编译等待编译结束编译成功在build文件下会出现一个新文件夹Debug.win32,里面就是编译
Cocos2d-x CCControlPotentiometer之圆形音量button及特效
1. 圆形音量button事实上作者的本意应该是叫做“电位计button”。可是我觉得它和我们的圆形音量button非常像,所以就这么叫它吧~先看效果:好了,不多解释,本篇到此为止。(旁白: 噗。就这样结束了?)啊才怪~我们来看看代码:[cpp] viewplaincopyprint?CCContro
Cocos2d-x入门教程二简单的静态显示对象
原文链接:http://www.cnblogs.com/physwf/archive/2013/04/26/3043912.html为了进一步深入学习贯彻Cocos2d,我们将自己写一个场景类,但我们不会走的太远,凡是都要循序渐进,哪怕只前进一点点,那也至少是前进了,总比贪多嚼不烂一头雾水的好。在上一节中我们建
  • • 如何使用CCRenderTexture创建动态纹理 …
  • • Cocos-code-ide使用入门学习
  • • Cocos2D-x-3.0 编译(Win7)
  • • Cocos2d-x 2 0 在Windows平台下的使用
  • • quick-cocos2d-x实例之挑战记忆极限设计…
  • • Cocos2d-x 3 X CMake MinGW版本编译运行
  • • vs 2013 编译cocos2d-x-3.9
  • • cocos2d-x游戏开发系列教程-超级玛丽01…
  • • Cocos2d-x CCControlPotentiometer之圆…
  • • Cocos2d-x入门教程二简单的静态显示对象
  • • cocos2d-x中CCScale9Sprite的另一种实现
  • • Cocos2d-x v2.2.2版本+Win7+VS2010环境…
  • • Ubuntu14.04+eclipse下cocos2d-x3.0正式…
  • • 分别基于WIN32 API界面编程和Cocos2d-x…
  • • Cocos2d-x 开发小记二:控件
  • • Cocos2d-x 开发小记一:基本动作
  • • 买Cocos2d-x视频课程送纸质图书
  • • ‎Cocos2d-x 学习笔记(11.10) Spawn

Cocos2d-x 3.x新事件分发机制总结的更多相关文章

  1. 使用Html5多媒体实现微信语音功能

    这篇文章主要介绍了使用Html5多媒体实现微信语音功能,需要的朋友可以参考下

  2. HTML5 canvas 瀑布流文字效果的示例代码

    这篇文章主要介绍了HTML5 canvas 瀑布流文字效果的示例代码的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  3. HTML5自定义视频播放器源码

    这篇文章主要介绍了HTML5自定义视频播放器源码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  4. HTML5自定义mp3播放器源码

    这篇文章主要介绍了HTML5自定义mp3播放器源码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  5. html5自定义video标签的海报与播放按钮功能

    这篇文章主要介绍了html5自定义video标签的海报与播放按钮功能,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  6. 详解HTML5中CSS外观属性

    这篇文章主要介绍了HTML5中CSS外观属性的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,,需要的朋友可以参考下

  7. CSS中实现动画效果-附案例

    这篇文章主要介绍了 CSS中实现动画效果并附上案例代码及实现效果,就是CSS动画样式处理,动画声明需要使用@keyframes name,后面的name是人为定义的动画名称,下面我们来看看文章的具体实现内容吧,需要的小伙伴可以参考一下

  8. 详解使用postMessage解决iframe跨域通信问题

    这篇文章主要介绍了详解使用postMessage解决iframe跨域通信问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  9. HTML5数字输入仅接受整数的实现代码

    这篇文章主要介绍了HTML5数字输入仅接受整数的实现代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  10. h5页面背景图很长要有滚动条滑动效果的实现

    这篇文章主要介绍了h5页面背景图很长要有滚动条滑动效果的实现,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

随机推荐

  1. 【cocos2d-x 3.x 学习笔记】对象内存管理

    Cocos2d-x的内存管理cocos2d-x中使用的是上面的引用计数来管理内存,但是又增加了一些自己的特色。cocos2d-x中通过Ref类来实现引用计数,所有需要实现内存自动回收的类都应该继承自Ref类。下面是Ref类的定义:在cocos2d-x中创建对象通常有两种方式:这两中方式的差异可以参见我另一篇博文“对象创建方式讨论”。在cocos2d-x中提倡使用第二种方式,为了避免误用第一种方式,一般将构造函数设为protected或private。参考资料:[1]cocos2d-x高级开发教程2.3节[

  2. 利用cocos2dx 3.2开发消灭星星六如何在cocos2dx中显示中文

    由于编码的不同,在cocos2dx中的Label控件中如果放入中文字,往往会出现乱码。为了方便使用,我把这个从文档中获取中文字的方法放在一个头文件里面Chinese.h这里的tex_vec是cocos2dx提供的一个保存文档内容的一个容器。这里给出ChineseWords,xml的格式再看看ChineseWord的实现Chinese.cpp就这样,以后在需要用到中文字的地方,就先include这个头文件然后调用ChineseWord函数,获取一串中文字符串。

  3. 利用cocos2dx 3.2开发消灭星星七关于星星的算法

    在前面,我们已经在GameLayer中利用随机数初始化了一个StarMatrix,如果还不知道怎么创建星星矩阵请回去看看而且我们也讲了整个游戏的触摸事件的派发了。

  4. cocos2dx3.x 新手打包APK注意事项!

    这个在编译的时候就可以发现了比较好弄这只是我遇到的,其他的以后遇到再补充吧。。。以前被这两个问题坑了好久

  5. 利用cocos2dx 3.2开发消灭星星八游戏的结束判断与数据控制

    如果你看完之前的,那么你基本已经拥有一个消灭星星游戏的雏形。开始把剩下的两两互不相连的星星消去。那么如何判断是GameOver还是进入下一关呢。。其实游戏数据贯穿整个游戏,包括星星消除的时候要加到获得分数上,消去剩下两两不相连的星星的时候的加分政策等,因此如果前面没有做这一块的,最好回去搞一搞。

  6. 利用cocos2dx 3.2开发消灭星星九为游戏添加一些特效

    needClear是一个flag,当游戏判断不能再继续后,这个flag变为true,开始消除剩下的星星clearSumTime是一个累加器ONE_CLEAR_TIME就是每颗星星消除的时间2.连击加分信息一般消除一次星星都会有连击信息和加多少分的信息。其实这些combo标签就是一张图片,也是通过控制其属性或者runAction来实现。源码ComboEffect.hComboEffect.cpp4.消除星星粒子效果消除星星时,为了实现星星爆裂散落的效果,使用了cocos2d提供的粒子特效引擎对于粒子特效不了

  7. 02 Cocos2D-x引擎win7环境搭建及创建项目

    官网有搭建的文章,直接转载记录。环境搭建:本文介绍如何搭建Cocos2d-x3.2版本的开发环境。项目创建:一、通过命令创建项目前面搭建好环境后,怎样创建自己的Cocos2d-x项目呢?先来看看Cocos2d-x3.2的目录吧这就是Cocos2d-x3.2的目录。输入cocosnew项目名–p包名–lcpp–d路径回车就创建成功了例如:成功后,找到这个项目打开proj.win32目录下的Hello.slnF5成功了。

  8. 利用cocos2dx 3.2开发消灭星星十为游戏添加音效项目源码分享

    一个游戏,声音也是非常的重要,其实cocos2dx里面的简单音效引擎的使用是非常简单的。我这里只不过是用一个类对所有的音效进行管理罢了。Audio.hAudio.cpp好了,本系列教程到此结束,第一次写教程如有不对请见谅或指教,谢谢大家。最后附上整个项目的源代码点击打开链接

  9. 03 Helloworld

    程序都有一个入口点,在C++就是main函数了,打开main.cpp,代码如下:123456789101112131415161718#include"main.h"#include"AppDelegate.h"#include"cocos2d.h"USING_NS_CC;intAPIENTRY_tWinMain{UNREFERENCED_ParaMETER;UNREFERENCED_ParaMETER;//createtheapplicationinstanceAppDelegateapp;return

  10. MenuItemImage*图标菜单创建注意事项

    学习cocos2dx,看的是cocos2d-x3.x手游开发实例详解,这本书错误一大把,本着探索求知勇于发现错误改正错误的精神,我跟着书上的例子一起调试,当学习到场景切换这个小节的时候,出了个错误,卡了我好几个小时。

返回
顶部