Cocos2d-x3.1下实现相似iOS页面滑动指示圆点
原文地址: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页面滑动指示圆点的更多相关文章
- ios 页面滑动到底部无法往上滚的问题
简单说明:当h5端使用vue-infinite-scroll 插件 做滚动加载 如:页面布局 <header></header> <div ...
- 微信下输入法在IOS和安卓下的诡异
1.验证window.innerHeight 系统版本 iOS9.1.1 安卓4.4.4 没有输入法的情况下 504 567 有输入法的情况下 208 273 看来两者的window.innerHei ...
- iOS页面间传值的六种方式
一般ios页面间的传值方式分为6种:1.属性传值:2.block:3.delegate:4.UserDefault:5.单例:6.通知. 0&1.block 先说我最常用的block吧,属性传 ...
- iOS页面切换动画实现方式。
iOS页面切换动画实现方式. 1.使用UIView animateWithDuration:animations:completion方法 Java代码 [UIView animateWithDura ...
- iOS 页面流畅技巧(1)
一.屏幕显示图像原理 首先明确两个概念:水平同步信号.垂直同步信号. CRT 的电子枪按照上图中的方式,从上到下一行一行的扫描,扫描完成后显示器就呈现一帧画面,随后电子枪回到初始位置继续下一次的扫描. ...
- IOS的H5页面滑动不流畅的问题:
IOS的H5页面滑动不流畅的问题: -webkit-overflow-scrolling : touch; 需要滑动的是哪块区域,就在哪里加上这段代码就OK
- iOS页面传值-wang
iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值:1.委托delegate方式:2.通知notific ...
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
iOS页面间传值实现方法:1.通过设置属性,实现页面间传值:2.委托delegate方式:3.通知notification方式:4.block方式:5.UserDefault或者文件方式:6.单例模式 ...
- iOS页面传值方式
普遍传值方式如下: 1.委托delegate方式: 2.通知notification方式: 3.block方式: 4.UserDefault或者文件方式: 5.单例模式方式: 6.通过设置属性,实现页 ...
随机推荐
- Android学习笔记之GridView的使用具体解释
(1)创建布局代码例如以下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android&quo ...
- android5.0 BLE 蓝牙4.0+浅析demo搜索(一)
作者:Bgwan链接:https://zhuanlan.zhihu.com/p/23341414来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 作者:Bgwan 莳萝花 ...
- 安装及XShell软件的配置
Linux系统centOS7在虚拟机下的安装及XShell软件的配置 前面的话 本文将详细介绍Linux系统centOS7在虚拟机下的安装 准备工作 [系统下载] 在安装centOS7之前,首先在 ...
- keil出现蓝色小箭头
- word中公式的排版及标题列表
1.首先建好你的标题,如标题1,标题2等等,你能够依次改变它们的字体,段落等格式,新建格式例如以下图所看到的 红圈处即建立新的格式,你能够建立不论什么你想要的格式,非常方便: 2.当你建立好了多个标题 ...
- hprof教程 分类: B1_JAVA 2015-03-02 12:18 444人阅读 评论(0) 收藏
大部分内容参考http://www.linuxidc.com/Linux/2012-04/58178.htm J2SE中提供了一个简单的命令行工具来对java程序的cpu和heap进行 profili ...
- 从Lua调用C
从Lua调用C: 方式:C函数从栈中获取函数參数(第一个參数总是局部栈的索引1),将结果压入栈中,C函数须要返回结果数量. 每一个函数都有自己的局部私有栈 样例: static int l_sin(l ...
- [Recompose] Flatten a Prop using Recompose
Learn how to use the ‘flattenProp’ higher order component to take a single object prop and spread ea ...
- 【solr专题之二】配置文件:solr.xml solrConfig.xml schema.xml 分类: H4_SOLR/LUCENCE 2014-07-23 21:30 1959人阅读 评论(0) 收藏
1.关于默认搜索域 If you are using the Lucene query parser, queries that don't specify a field name will use ...
- jquery-11 如何实现标签的鼠标拖动效果
jquery-11 如何实现标签的鼠标拖动效果 一.总结 一句话总结:核心原理:1.标签实现绝对定位,位置的话跟着鼠标走.2.点击标签的话,给标签绑定事件,停止按住鼠标的话,解除绑定的事件. 1.事件 ...