Cocos2d-x的SneakyInput
来源:互联网 发布:NSIS软件 编辑:程序博客网 时间:2024/05/17 03:04
SneakyInput是虚拟摇杆库。
SneakyInput是2dx里面的虚拟手柄。但是从官网下载下来2dx的版本太旧,要对他进行修改,适用于cocos2d-x 2.1.4版本。理论上适用所有的2dx的2.1+版本。
下载地址:点击打开链接
废话少说,直接进入正题:
声明:
#include "SneakyInput/SneakyJoystickSkinnedBase.h"#include "SneakyInput/SneakyButtonSkinnedBase.h"SneakyButton *button;SneakyJoystick *joystick;
定义SneakyInput的摇杆和获取摇杆的数据:
定义:
SneakyJoystickSkinnedBase *joystickBase = new SneakyJoystickSkinnedBase(); joystickBase->autorelease(); joystickBase->init(); joystickBase->setBackgroundSprite(CCSprite::create("b.png")); // 底座 joystickBase->setThumbSprite(CCSprite::create("f.png")); // 操控杆 joystickBase->setPosition(CCPointMake(48, 48));joystick = new SneakyJoystick(); joystick->autorelease(); joystick->initWithRect(CCRectMake(0,0,64,64)); joystickBase->setJoystick(joystick); //是否自动回到中心 joystick->setAutoCenter(true); //是否支持死亡区域,该区域不会触发 joystick->setHasDeadzone(true); //死亡区域半径 joystick->setDeadRadius(10); this->addChild(joystickBase);
获取数据:
joystick->getVelocity();
定义按钮:
//按钮按钮皮肤SneakyButtonSkinnedBase *buttonBase = new SneakyButtonSkinnedBase(); buttonBase->autorelease(); buttonBase->init(); buttonBase->setDefaultSprite(CCSprite::create("default.png")); buttonBase->setActivatedSprite(CCSprite::create("activated.png")); buttonBase->setPressSprite(CCSprite::create("press.png")); buttonBase->setPosition(CCPointMake(480-48, 48)); //按钮button = new SneakyButton(); button->autorelease(); button->initWithRect(CCRectMake(0,0,32,32)); button->setIsToggleable(false); //设置在按下时,是否保持按下状态button->setIsHoldable(true); buttonBase->setButton(button); this->addChild(buttonBase);
获取数据:
button->getIsActive();//按钮是否按下
一般获取数据的地方都是在update(float dt) 里面获取。
void HelloWorld::update(float dt) { if (button->getIsActive()){CCLog("fire!");}CCPoint scaledV = ccpMult(joystick->getVelocity(), 1); float x = scaledV.x;float y = scaledV.y;CCLog("%f---%f",x,y);}下载地址:点击打开链接
- Cocos2d-x的SneakyInput
- cocos2d-x的初步学习十三之虚拟摇杆SneakyInput
- cocos2d-x(2.1.4)之虚拟摇杆SneakyInput
- 虚拟摇杆SneakyInput的多点触摸问题
- 【cocos2d-x】cocos2d-x的内存管理
- 【Cocos2d-x】cocos2d-x的拷贝机制
- cocos2d-x的action
- cocos2d-x的transitionScene
- cocos2d-x的场景
- cocos2d-x的工具
- cocos2d-x的定时器
- cocos2d-x 的动画
- cocos2d-x 的坐标
- Cocos2d-x的基本概念
- Cocos2d-X的精灵
- Cocos2d-X的shader
- cocos2d-x的scheduleSelector
- cocos2d-x的坑
- golang精华资源
- 关于QWS
- TI 16位 3.3V--5V 电平转换芯片 SN74ALVC164245
- RMAN 系列(五),RMAN 还原 与 恢复
- iphone开发中的一些小技巧
- Cocos2d-x的SneakyInput
- VPS的CentOS中时间同步方法
- Launch an NSTask and bring it to front
- 系统启动过程简介
- html设置元素水平或垂直居中
- Media Foundation系列文章索引
- iOS提交iTunes审核时出现Invalid Binary错误
- java 文件加密解密
- windows linux 文件传输