Cocos2d-x的SneakyInput
来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:43 点击:次
SneakyInput是虚拟摇杆库。
p>
p>SneakyInput是2dx里面的虚拟手柄。但是从官网下载下来2dx的版本太旧,要对他进行修改,适用于cocos2d-x 2.1.4版本。理论上适用所有的2dx的2.1+版本。
p>
p>
p>
p>废话少说,直接进入正题:
p>
p>声明:
p>
p>[cpp]
p>#include "SneakyInput/SneakyJoystickSkinnedBase.h"
p>#include "SneakyInput/SneakyButtonSkinnedBase.h"
p>
p>SneakyButton *button;
p>SneakyJoystick *joystick;
p>
p>
p>定义SneakyInput的摇杆和获取摇杆的数据:
p>
p>定义:
p>
p>[cpp]
p>SneakyJoystickSkinnedBase *joystickBase = new SneakyJoystickSkinnedBase();
p>joystickBase->autorelease();
p>joystickBase->init();
p>joystickBase->setBackgroundSprite(CCSprite::create("b.png")); // 底座
p>joystickBase->setThumbSprite(CCSprite::create("f.png")); // 操控杆
p>joystickBase->setPosition(CCPointMake(48, 48));
p>
p>joystick = new SneakyJoystick();
p>joystick->autorelease();
p>joystick->initWithRect(CCRectMake(0,0,64,64));
p>joystickBase->setJoystick(joystick);
p>//是否自动回到中心
p>joystick->setAutoCenter(true);
p>//是否支持死亡区域,该区域不会触发
p>joystick->setHasDeadzone(true);
p>//死亡区域半径
p> joystick->setDeadRadius(10);
p>
p>this->addChild(joystickBase);
p>
p>获取数据:
p>[cpp]
p>joystick->getVelocity();
p>
p>定义SneakyInput的按钮和获取按钮的数据:
p>定义按钮:
p>
p>[cpp]
p><span style="white-space:pre"> </span>//按钮按钮皮肤
p> SneakyButtonSkinnedBase *buttonBase = new SneakyButtonSkinnedBase();
p> buttonBase->autorelease();
p> buttonBase->init();
p> buttonBase->setDefaultSprite(CCSprite::create("default.png"));
p> buttonBase->setActivatedSprite(CCSprite::create("activated.png"));
p> buttonBase->setPressSprite(CCSprite::create("press.png"));
p>
p> buttonBase->setPosition(CCPointMake(480-48, 48));
p>
p> //按钮
p> button = new SneakyButton();
p> button->autorelease();
p> button->initWithRect(CCRectMake(0,0,32,32));
p> button->setIsToggleable(false);
p> //设置在按下时,是否保持按下状态
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>