首页 > 其他分享 >cocos2dx之创建CCControlSlider

cocos2dx之创建CCControlSlider

时间:2023-08-25 15:08:00浏览次数:50  
标签:control cocos2dx CCControlSlider ccp slider 创建 png size


采用CCControlSlider创建,代码如下:

CCControlSlider *slider = CCControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");

	slider->setAnchorPoint(ccp(0.5, 1.0f));
	slider->setPosition(ccp(visibleSize.width / 2.0f, visibleSize.height / 2.0f));
	slider->setMinimumValue(0.1f);
	slider->setMaximumValue(100.0f);
	slider->setTag(1);

	slider->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::valueChange), CCControlEventValueChanged);

	this->addChild(slider, 1);

 

/** Kinds of possible events for the control objects. */
enum 
{
    CCControlEventTouchDown           = 1 << 0,    // A touch-down event in the control.
    CCControlEventTouchDragInside     = 1 << 1,    // An event where a finger is dragged inside the bounds of the control.
    CCControlEventTouchDragOutside    = 1 << 2,    // An event where a finger is dragged just outside the bounds of the control. 
    CCControlEventTouchDragEnter      = 1 << 3,    // An event where a finger is dragged into the bounds of the control.
    CCControlEventTouchDragExit       = 1 << 4,    // An event where a finger is dragged from within a control to outside its bounds.
    CCControlEventTouchUpInside       = 1 << 5,    // A touch-up event in the control where the finger is inside the bounds of the control. 
    CCControlEventTouchUpOutside      = 1 << 6,    // A touch-up event in the control where the finger is outside the bounds of the control.
    CCControlEventTouchCancel         = 1 << 7,    // A system event canceling the current touches for the control.
    CCControlEventValueChanged        = 1 << 8      // A touch dragging or otherwise manipulating a control, causing it to emit a series of different values.
};

 

 

还可以建立色盘,利用CCControlColourPicker,具体代码如下:

void MyControlLayerItem::initLayer() {

	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCControlColourPicker *control = CCControlColourPicker::create();
	control->setPosition(ccp(size.width / 3.0f, size.height / 3.0f));
	control->setColor(ccc3(255, 0, 0));
	control->addTargetWithActionForControlEvents(
												 this,
												 cccontrol_selector(MyControlLayerItem::valueChange),
												 CCControlEventValueChanged);
	this->addChild(control, 2);
}

 

标签:control,cocos2dx,CCControlSlider,ccp,slider,创建,png,size
From: https://blog.51cto.com/u_13566975/7230887

相关文章

  • cocos2dx之利用CCSpriteBatchNode创建多个Sprite
    相关技术文档,我们在渲染一个图片的时候经常都是一次渲染一个,如果图片资源很多的话,自然降低了效率,这个时候,我们想,要是能一次渲染完毕,以后要再创建的时候,就不需要再渲染就好了,刚好提供了一个类:CCSpriteBatchNode,一次渲染多个,具体看如下代码:voidMyBathNodeLayer::initLayer(){ CCSi......
  • cocos2dx之CCLayerMultiplex
    刚开始接触这个东西,弄了好久都没有弄好,我自己太笨了,现在我将如何创建一个CCLayerMultiplex过程写出来,代码如下:CCLayer*mainLayer=newMenuDemo;CCLayer*menu1=newMenuDemoItem1;CCLayer*menu2=newMenuDemoItem2;CCLayer*menu3=newMenuDemoItem3;......
  • cocos2dx 之如何创建label 做计分板
    首先创建label:gameScoreLabel=CCLabelTTF::create("0","Arial",30);gameScoreLabel->setColor(ccRED);gameScoreLabel->retain();gameScoreLabel->setPosition(ccp(s.width/6,s.height/6));this->addChild(gameS......
  • cocos2dx之播放音乐
    在游戏时,背景音乐应该说是必不可少的,但是在cocos2dx中如何播放音乐呢,我们看如下代码:CCSize>>如果用stop的话,那么我得再重新playmusic了!关于背景音乐,cocos2dx在不同平台下支持的格式:Android:mp3,wav,3gpIos:mp3,cafWin32:MID,WAV关于音效,cocos2dx在不......
  • sql server创建视图操作
    1、什么是视图视图就是一个虚拟的数据表,该数据表中的数据记录是有一条查询语句的查询结果得到的。2、创建视图准则创建视图需要考虑一下准则:  #视图名称必须遵循标识符的规则,该名称不得与该架构的如何表的名称相同  #你可以对其他......
  • 微调llama2模型教程:创建自己的Python代码生成器
    本文将演示如何使用PEFT、QLoRa和Huggingface对新的lama-2进行微调,生成自己的代码生成器。所以本文将重点展示如何定制自己的llama2,进行快速训练,以完成特定任务。 https://avoid.overfit.cn/post/9794c9eef1df4e55adf514b3d727ee3b......
  • 创建第一个Django app-part5
    自动化测试开始第一个测试首先有一个bugpython3manage.pyshell创建一个测试来暴露这个bug将下面的代码写入polls应用里的tests.py文件内点击查看代码fromdjango.testimportTestCase#Createyourtestshere.importdatetimefromdjango.utilsimporttim......
  • Red Hat8.8 安装 Oracle19C,配置开机自动启动,创建数据库,调整内核参数
    1.下载rpm包oracle-database-ee-19c-1.0-1.x86_64.rpm2.上传rpm包上传下载的rpm包到响应目录,例如:/home3.安装依赖上传compat-libcap1-1.10-7.el7.x86_64.rpm和compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm包的相应目录例如:/home安装上传的两个rpm包#安......
  • 如何使用 ABAP Function Module SEO_CLASS_CREATE_COMPLETE 创建 ABAP class
    SEO_CLASS_CREATE_COMPLETE函数模块用于在SAP系统中创建一个完整的SAP类。在SAPABAP中,类是面向对象编程的基本构建块,它允许开发者将数据和行为组织到一个单一的实体中。SAP的类通常用于描述业务对象、数据结构和业务逻辑,以实现灵活性和可维护性。SEO_CLASS_CREATE_COMPLETE函数......
  • Linux下添加磁盘创建lvm分区
    shell>fdisk/dev/xvdb####选择磁盘Command(mforhelp):m####帮助Commandactionatoggleabootableflagbeditbsddisklabelctogglethedoscompatibilityflagddeletea......