博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于CCRANDOM_0_1
阅读量:6972 次
发布时间:2019-06-27

本文共 1819 字,大约阅读时间需要 6 分钟。

CCRANDOM_0_1的范围是[0,1)包括0但不包括1

CCRANDOM_0_1() * 1400.0f / 100.0f是0-13

另外每次随机都是相同的数,要随机下种子

srand((unsigned int)time(NULL));    for (int i = 0; i < 100; i++)    {        //CCRANDOM_0_1是[0,1)        //log("%d", (int)(CCRANDOM_0_1()*2));        //                int idx = (int)(CCRANDOM_0_1() * 1400.0f / 100.0f);        log("%d",idx);    }

 递归一个动画,实现动画不停的播放,动画间隔时间为随机数:

callFunc callFuncN表示里面添加一个节点作为参数,传递到调用方法,均为sequence的回调函数,意思为做完这个动作,再执行这个函数。

void MainScene::aciton_dishu(Node* dishu){	//dishu = Sprite::createWithSpriteFrameName("mouse1.png");	Vector
vec(6); char str2[100] = { 0 }; for (int i = 0; i < 6; i++) { sprintf(str2, "mouse%d.png", (i + 1)); auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str2); vec.pushBack(frame); } float deayT = CCRANDOM_0_1() * 10; log("tag,dely-->%d,%f", dishu->getTag(),deayT); auto animation = Animation::createWithSpriteFrames(vec, 0.2f); //callFunc callFunN callFunNC分别为0,1,2个参数 auto action = Animate::create(animation); Sequence *seq = Sequence::create( DelayTime::create(deayT), action, action->reverse(), //DelayTime::create(deayT), CallFunc::create(std::bind(&MainScene::aciton_dishu, this, dishu)), nullptr); dishu->runAction(seq);}

  3.2中callFunc可以通过std::bind绑定任意个数参数到函数里。this是指函数对象指针,后面的是函数参数列表,个人觉得还是CallFunc好用点,CallFuncN不好理解

void ActionRepeatForever::onEnter(){    ActionsDemo::onEnter();    centerSprites(1);    auto action = Sequence::create(        DelayTime::create(1),        CallFunc::create( std::bind( &ActionRepeatForever::repeatForever, this, _grossini) ),        nullptr);    _grossini->runAction(action);}void ActionRepeatForever::repeatForever(Node* sender){    auto repeat = RepeatForever::create( RotateBy::create(1.0f, 360) );    sender->runAction(repeat);}

  

转载于:https://www.cnblogs.com/as3lib/p/3917849.html

你可能感兴趣的文章
常用数据库语句
查看>>
jQuery Easy UI 开发笔记
查看>>
26、ASP.NET MVC入门到精通——后台管理区域及分离、Js压缩、css、jquery扩展
查看>>
Python标准库:内置函数repr(object)
查看>>
【SpringMVC】SpringMVC系列14之SpringMVC国际化
查看>>
Codeforces Beta Round #1 B. Spreadsheets 模拟
查看>>
辛星深入分析vim的自己主动补全功能以及vim的映射
查看>>
ADCD 1.9 ZOS 配置 CTCI-W32 TCPIP 网络
查看>>
ASP.NET MVC之如何看待内置配置来提高性能优化(四)
查看>>
IOS-NSRunLoop
查看>>
Centos6.5更新e1000网卡驱动
查看>>
jz2440: linux/arch/arm/下面的plat-和mach-
查看>>
Linux中文件描述符fd和文件指针flip的理解
查看>>
Btrace是一个实时监控工具
查看>>
Download file using libcurl in C/C++
查看>>
电Call记录统计查询sql
查看>>
JS面试题-算法台阶问题
查看>>
[转] c# 的传递参数值传递与传递引用的区别,ref与out区别
查看>>
iOS开发UI篇—在UItableview中实现加载更多功能
查看>>
Java计算文件的SHA码和MD5码
查看>>