原文地址:http://blog.csdn.net/qqmcy/article/details/37612457

代码下载:http://download.csdn.net/detail/qqmcy/7613835

SliderIndicatorLayout.h

//
// SliderIndicatorLayout.h
// ht_mobile_cpp
//
// Created by 杜甲 on 14-7-9.
//
// #ifndef __ht_mobile_cpp__SliderIndicatorLayout__
#define __ht_mobile_cpp__SliderIndicatorLayout__ #include "cocos2d.h"
#include "ui/CocosGUI.h" USING_NS_CC; class SliderIndicatorLayout:public ui::Layout
{ public: CREATE_FUNC(SliderIndicatorLayout); virtual bool init();
//加入指示圆点个数
void addIndicator(int num);
//选中的第几个
void changeIndicator(int index); private:
Size winSize;
float radius; }; #endif /* defined(__ht_mobile_cpp__SliderIndicatorLayout__) */

SliderIndicatorLayout.cpp

//
// SliderIndicatorLayout.cpp
// ht_mobile_cpp
//
// Created by 杜甲 on 14-7-9.
//
// #include "SliderIndicatorLayout.h"
#include "SliderIndicator.h" bool SliderIndicatorLayout::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!ui::Layout::init()); setLayoutType(cocos2d::ui::Layout::Type::VERTICAL);
winSize = Director::getInstance()->getWinSize(); radius = winSize.height / 130; bRet = true;
} while (0);
return bRet;
} void SliderIndicatorLayout::addIndicator(int num)
{
setSize(Size(radius * 2, radius*3 * num));
for (int i = 0 ; i < num; i++)
{
auto indicator = SliderIndicator::create();
indicator->setSize(Size(radius, radius));
indicator->setCircleColor(Color4B(255, 40, 255, 255));
indicator->setTag(i);
addChild(indicator); auto lp_indicator = ui::LinearLayoutParameter::create();
lp_indicator->setGravity(cocos2d::ui::LinearLayoutParameter::LinearGravity::TOP);
lp_indicator->setMargin(ui::Margin(0,radius * 2.0f,0,0));
if (i == 0)
{
lp_indicator->setMargin(ui::Margin(0, 0,0,0)); }
indicator->setLayoutParameter(lp_indicator); }
changeIndicator(0);
} void SliderIndicatorLayout::changeIndicator(int index)
{
for (int i = 0; i < getChildren().size(); i++)
{
auto indicator = dynamic_cast<SliderIndicator*>(getChildByTag(i));
indicator->setCircleColor(Color4B(255, 40, 255, 25));
if (i == index)
{
indicator->setCircleColor(Color4B(255, 40, 255, 255));
} } }

SliderIndicator.h

//
// SliderIndicator.h
// ht_mobile_cpp
//
// Created by 杜甲 on 14-7-9.
//
// #ifndef __ht_mobile_cpp__SliderIndicator__
#define __ht_mobile_cpp__SliderIndicator__ #include "cocos2d.h"
#include "ui/CocosGUI.h" USING_NS_CC; class SliderIndicator:public ui::Layout
{ public: CREATE_FUNC(SliderIndicator); virtual bool init(); CC_SYNTHESIZE(Color4B, _circleColor, CircleColor); protected: void onDraw(const Mat4 &transform, bool transformUpdated);
void draw(Renderer *renderer, const Mat4 &transform, bool transformUpdated); CustomCommand _customCommand;
}; #endif /* defined(__ht_mobile_cpp__SliderIndicator__) */

SliderIndicator.cpp

//
// SliderIndicator.cpp
// ht_mobile_cpp
//
// Created by 杜甲 on 14-7-9.
//
// #include "SliderIndicator.h"
bool SliderIndicator::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!ui::Layout::init()); bRet = true;
} while (0);
return bRet;
} void SliderIndicator::draw(Renderer *renderer, const Mat4 &transform, bool transformUpdated)
{ _customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(SliderIndicator::onDraw, this,transform,transformUpdated);
renderer->addCommand(&_customCommand); } void SliderIndicator::onDraw(const cocos2d::Mat4 &transform, bool transformUpdated)
{ Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); DrawPrimitives::setDrawColor4B(_circleColor.r, _circleColor.g, _circleColor.b, _circleColor.a); DrawPrimitives::drawSolidCircle( Vec2(0,0), director->getWinSize().height / 130, CC_DEGREES_TO_RADIANS(90), 50, 1.0f, 1.0f); //end draw
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }

Cocos2d-x3.1下实现相似iOS页面滑动指示圆点的更多相关文章

  1. ios 页面滑动到底部无法往上滚的问题

    简单说明:当h5端使用vue-infinite-scroll 插件 做滚动加载                如:页面布局  <header></header> <div ...

  2. 微信下输入法在IOS和安卓下的诡异

    1.验证window.innerHeight 系统版本 iOS9.1.1 安卓4.4.4 没有输入法的情况下 504 567 有输入法的情况下 208 273 看来两者的window.innerHei ...

  3. iOS页面间传值的六种方式

    一般ios页面间的传值方式分为6种:1.属性传值:2.block:3.delegate:4.UserDefault:5.单例:6.通知. 0&1.block 先说我最常用的block吧,属性传 ...

  4. iOS页面切换动画实现方式。

    iOS页面切换动画实现方式. 1.使用UIView animateWithDuration:animations:completion方法 Java代码 [UIView animateWithDura ...

  5. iOS 页面流畅技巧(1)

    一.屏幕显示图像原理 首先明确两个概念:水平同步信号.垂直同步信号. CRT 的电子枪按照上图中的方式,从上到下一行一行的扫描,扫描完成后显示器就呈现一帧画面,随后电子枪回到初始位置继续下一次的扫描. ...

  6. IOS的H5页面滑动不流畅的问题:

    IOS的H5页面滑动不流畅的问题: -webkit-overflow-scrolling : touch; 需要滑动的是哪块区域,就在哪里加上这段代码就OK

  7. iOS页面传值-wang

    iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值:1.委托delegate方式:2.通知notific ...

  8. iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)

    iOS页面间传值实现方法:1.通过设置属性,实现页面间传值:2.委托delegate方式:3.通知notification方式:4.block方式:5.UserDefault或者文件方式:6.单例模式 ...

  9. iOS页面传值方式

    普遍传值方式如下: 1.委托delegate方式: 2.通知notification方式: 3.block方式: 4.UserDefault或者文件方式: 5.单例模式方式: 6.通过设置属性,实现页 ...

随机推荐

  1. andriod first app-computer

    andriod first app-computer 个人信息:就读于燕大本科软件project专业 眼下大三; 本人博客:google搜索"cqs_2012"就可以; 个人爱好: ...

  2. Windows Vista下UIPI和Windows消息的故事(UIPI默认情况下会禁止所有高于WM_USER的消息)

    一. 什么是UIPI UIPI指User Interface Privilege Isolation(用户界面特权隔离),是Windows Vista 新引入的一种安全特性.用于拦截接收比自身进程MI ...

  3. bitnami WAMP stack使用方法(转)

    想学习PHP,在网上找了些资料看了一下.介绍一个简单快速的服务器搭建方法,基于WAMP(WINDOWS+APATCH_MYSQL/MARIADB+PERL/PHP/PYTHON)架构.对应的也有LAM ...

  4. [Jenkins] Define a pipeline

    node{ stage 'checkout' git '[github_url]' def project_path="[project_path]" // everythin i ...

  5. 关于CoordinatorLayout与Behavior的一点分析

    Behavior是Android新出的Design库里新增的布局概念.Behavior只有是CoordinatorLayout的直接子View才有意义.可以为任何View添加一个Behavior.Be ...

  6. 如何去掉windows2003的自动锁定(每离开一会都会出现这个界面,不想让它出现)

    http://zhidao.baidu.com/link?url=SOCv57C-hX_3f0Xl0J0RFIVXpowXk73zdQd2B-wMUzYOm5E_N397bw_UkX4uLPlAiWQ ...

  7. Mybatis找不到参数错误:There is no getter for property named 'categoryId' in 'class java.lang.Integer'。

    Mybatis找不到参数错误:There is no getter for property named 'categoryId' in 'class java.lang.Integer'. 错误Li ...

  8. js进阶 9-7 自动计算商品价值

    js进阶 9-7  自动计算商品价值 一.总结 一句话总结: 1.form表单控件value属性:属性可取值可赋值 2.文本onchange事件 3.form及form中控件通过name访问元素 二. ...

  9. php数学和时间常用函数有哪些(总结表)(看学习视频效率挺高的)(复习)

    php数学和时间常用函数有哪些(总结表)(看学习视频效率挺高的)(复习) 一.总结 一句话总结: 1.数学函数常用的6个:max().min().cell().floor().round().mt_r ...

  10. Python 库的使用 —— dis

    dis:Disassembler of Python byte code into mnemonics. Java.Python.Ruby 1.9 这些语言均使用了栈机器型的 VM.因为是基于栈的实现 ...