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.通过设置属性,实现页 ...
随机推荐
- Spark Streaming教程
废话不说,先来个示例,有个感性认识再介绍. 这个示例来自spark自带的example,基本步骤如下: (1)使用以下命令输入流消息: $ nc -lk 9999 (2)在一个新的终端中运行Net ...
- stm32的adc时钟周期,ADC_SampleTime_1Cycles5是多长时间
- <p><span style="font-size:14px">近期须要批量将PNM格式的文件转换成GIF文件。我尝试了例如以下的图像转换工具:</span></p>
近期须要批量将PNM格式的文件转换成GIF文件.我尝试了例如以下的图像转换工具: ImageBatch:全然免费,但只支持PNG JPEG BMP GIF四种格式 OfficeConverter:在线 ...
- php课程 3-12 回调参数怎么用
php课程 3-12 回调参数怎么用 一.总结 一句话总结:有时候需要在一个函数中使用另外一个函数,使用回调的话,那么那个函数的几十行代码就不用写了,其实很基础,就是函数名的字符串的替换,超级基础的. ...
- [Vue] Create Vue.js Layout and Navigation with Nuxt.js
Nuxt.js enables you to easily create layout and navigation by replacing the default App.vue template ...
- phoenixframe平台连接socketserver,并接收返回值的演示样例
package org.phoenix.cases.webservice; import java.util.LinkedList; import org.phoenix.action.WebElem ...
- iOS开发RunLoop学习:三:Runloop相关类(source和Observer)
一:RunLoop相关类: 其中:source0指的是非基于端口por,说白了也就是处理触摸事件,selector事件,source1指的是基于端口的port:是处理系统的一些事件 注意:创建一个Ru ...
- JSON入门之二:org.json的基本用法 分类: C_OHTERS 2014-05-14 11:25 6001人阅读 评论(0) 收藏
java中用于解释json的主流工具有org.json.json-lib与gson,本文介绍org.json的应用. 官方文档: http://www.json.org/java/ http://de ...
- PHP移动互联网开发笔记(3)——运算符与流程控制
一.PHP的运算符 PHP中有丰富的运算符集,它们中大部分直接来自于C语言.按照不同功能区分,运算符可以分为:算术运算符.字符串运算符.赋值运算符.位运算符.条件运算符,以及逻辑运算符等.当各种运算符 ...
- Mysql用户本机登陆不成功的解决
mysql新建一个用户,本机不能登陆,但是远程能够登陆,不知什么原因,最后查阅 http://blog.itpub.net/12679300/viewspace-1453490/ 这篇文章得以解决,进 ...