原文地址: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. 谈谈我对P2P网络借贷的一些看法

    北漂期间,只知道互联网金融非常火,相关创业公司和项目也非常多.2013年,最火的是余额宝等宝宝类产品.当时的收益率达到了7%,流动性如此高的情况下,竟达到这么高的收益率,我简直不敢相信.另外,当时考虑 ...

  2. 【26.83%】【Codeforces Round #380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. (八)RabbitMQ消息队列-通过Topic主题模式分发消息

    原文:(八)RabbitMQ消息队列-通过Topic主题模式分发消息 前两章我们讲了RabbitMQ的direct模式和fanout模式,本章介绍topic主题模式的应用.如果对direct模式下通过 ...

  4. [转载]剥析surging的架构思想

    1.前言 2.通信机制 2.1 简介      在单体应用中,模块之间的调用通信通过引用加载方法或者函数来实现,但是单体应用最终都会因为团队壮大,项目模块的扩展和部署等出现难以维护的问题.随着业务需求 ...

  5. CCPC2016长春站打铁记

    Day0 晚上到的长春.很冷.到了宾馆.放了行李.然后就去吃了点火锅.很好吃.在福建吃的都没有酱.但是回去后有点拉肚子..几个队友也有同样的反应.路过了吉大.拍了一张照片.哎.压力好大. Day1 来 ...

  6. QT学习记录之控件布局

    作者:朱金灿 来源:http://blog.csdn.net/clever101 想到控件布局就会想到Windows编程中要实现对话框上的控件的合理布局是一件多么艰难的事情.对此QT提出了一个很方便的 ...

  7. ant脚本中设置环境变量

    http://blog.csdn.net/quqi99/article/details/5329841

  8. [TypeScript] Simplify asynchronous callback functions using async/await

    Learn how to write a promise based delay function and then use it in async await to see how much it ...

  9. 授人玫瑰 手留余香 --纪念python3.2.3官方文档翻译结束

    当你点击看到这篇文章的时候.你已经得到了祝福. 一个来自夜深人静的码农,在2014年5月19号的01:18分.默默为你献上祝福. 希望你.我和他,每个在IT行业中奋斗的人.能找到属于自己一片天空. 在 ...

  10. head first c 笔记&lt;3&gt; 之做一件事并把它做好

    1.标准输入.输出与重定向 scanf()和printf()分别为标准输入输出.默认的会从键盘得到数据,在显示器输出数据,是fscanf()和fprintf()函数的特例. 我们也能够用重定向来改变默 ...