CCControlSwitch 开关
2013-04-08 19:31
501 查看
新建工程,名为testSwitch
修改HelloWorldScene.h
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
#include "cocos-ext.h"
class HelloWorld :
public cocos2d::CCLayer
{
public:
// Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)
virtual bool init();
// there's no 'id' in cpp, so we recommend to return the class instance pointer
static cocos2d::CCScene* scene();
// preprocessor macro for "static create()" constructor ( node() deprecated )
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__
修改HelloWorldScene.cpp
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace
cocos2d;
using namespace
CocosDenshion;
using namespace
extension;
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer =
HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return
false;
}
CCControlSwitch *pSwitch=CCControlSwitch::create(CCSprite::create("switch-mask.png"),
CCSprite::create("switch-on.png"),
CCSprite::create("switch-off.png"),
CCSprite::create("switch-thumb.png"),
CCLabelTTF::create("开",
"Arial-BoldMT", 16),
CCLabelTTF::create("关",
"Arial-BoldMT", 16)
);
pSwitch->setPosition(ccp(200,200));
//设置关闭状态
pSwitch->setOn(false);
//设置可操作
pSwitch->setEnabled(true);
//获取是否为打开(on)
CCLOG("是否打开状态:%i",pSwitch->isOn());
//获取当前开关状态是否为手动拖动开关进行的
CCLOG("是否手动拖动的开关:%i",pSwitch->hasMoved());
addChild(pSwitch);
return
true;
}
修改HelloWorldScene.h
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
#include "cocos-ext.h"
class HelloWorld :
public cocos2d::CCLayer
{
public:
// Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)
virtual bool init();
// there's no 'id' in cpp, so we recommend to return the class instance pointer
static cocos2d::CCScene* scene();
// preprocessor macro for "static create()" constructor ( node() deprecated )
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__
修改HelloWorldScene.cpp
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace
cocos2d;
using namespace
CocosDenshion;
using namespace
extension;
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer =
HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return
false;
}
CCControlSwitch *pSwitch=CCControlSwitch::create(CCSprite::create("switch-mask.png"),
CCSprite::create("switch-on.png"),
CCSprite::create("switch-off.png"),
CCSprite::create("switch-thumb.png"),
CCLabelTTF::create("开",
"Arial-BoldMT", 16),
CCLabelTTF::create("关",
"Arial-BoldMT", 16)
);
pSwitch->setPosition(ccp(200,200));
//设置关闭状态
pSwitch->setOn(false);
//设置可操作
pSwitch->setEnabled(true);
//获取是否为打开(on)
CCLOG("是否打开状态:%i",pSwitch->isOn());
//获取当前开关状态是否为手动拖动开关进行的
CCLOG("是否手动拖动的开关:%i",pSwitch->hasMoved());
addChild(pSwitch);
return
true;
}
相关文章推荐
- Cocos2d-x_CCControlSwitch(开关类)介绍
- 8.cocos2dx 开关 CCControlSwitch
- Cocos2d—X游戏开发之CCToggle(菜单标签切换)CCControlSwitch(开关切换)
- CCControlSwitch 开关
- cocos2dx 开关 CCControlSwitch
- Cocos2d-x学习笔记(12)(CCControlSwitch开关、CCControlSlider滑动条、CCControlButton按钮)
- Cocos2d-x学习笔记(12)(CCControlSwitch开关、CCControlSlider滑动条、CCControlButtonbutton)
- cocos2dx基础篇(10)——开关按钮CCControlSwitch
- Cocos2d—X游戏开发之CCToggle(菜单标签切换)CCControlSwitch(开关切换)(十二)
- Cocos2D-x 用CCControlSwitch设置音乐的开关
- cocos2d-x-2.0新增加了几个UI控件,这里我介绍下常用的这几个UI控件(CCControlSlider、CCControlSwitch、CCControlColourPicker)使用方法
- 关于CCControlSwitch设置在弹窗上后的触摸优先级问题
- CCControlExtension/CCControlSwitch
- cocos2dX UI控件之CCControlSwitch
- cocos2d-x-2.0 新增UI的使用方法(CCControlSlider、CCControlSwitch、CCControlColourPicker、ListView)
- CCControlSwitch学习笔记
- cocos2dx CCControlSwitch
- 和屌丝一起学cocos2dx-CCControlSwitch
- CCControlSwitch 的使用
- 我的Cocos2d-x学习笔记(十五)CCControlSlider、CCControlSwitch、CCScale9Sprite、CCControlButton