zoukankan      html  css  js  c++  java
  • 关于CCRANDOM_0_1

    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<SpriteFrame*> 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);
    }
    

      

  • 相关阅读:
    文件处理
    基本数据类型
    Python简介和入门
    了解计算机的发展历程
    工具类(MailUtils)发邮件
    文件上传和下载
    JavaWeb过滤器
    JavaWeb监听器
    JavaWeb的分页
    JdbcUtils(内部使用c3p0得到连接池对象datasource)的第三次修改---完成事务的处理
  • 原文地址:https://www.cnblogs.com/as3lib/p/3917849.html
Copyright © 2011-2022 走看看