zoukankan      html  css  js  c++  java
  • cocos2d-x帧动画实现(写下备忘)

    帧动画就是很多张png的序列图实现轮流播放产生动画效果。

    那么首先我们要一套动画的序列图,没有图的可以看引擎例子里面的图。很多张图我们可以采用TP工具将它们压缩到一张png里面去,这样程序只需要读取一次就行了,提高效率。

    动画是打地鼠地鼠出洞的表现,代码如下:

     

    //新的游戏动画:
    	//创建cache
    	CCSpriteFrameCache* cache=CCSpriteFrameCache::sharedSpriteFrameCache();
    	char strPlist[64]={0};
    	char strPng[64]={0};
    	sprintf(strPlist,"Game/Game_Resource.plist");
    	sprintf(strPng,"Game/Game_Resource.png");
    	cache->addSpriteFramesWithFile(strPlist,strPng);
    	//创建动画每一帧,从cache中读取
    	CCArray* animFrams=new CCArray(8);
    	char str[64]={0};
    	for (int i=0;i<3;i++)
    	{
    		sprintf(str,"mole_a%d.png",i);
    		CCLog(str);
    		CCSpriteFrame* frame=cache->spriteFrameByName(str);
    		animFrams->addObject(frame);
    	}
    	CCAnimation* animation=CCAnimation::createWithSpriteFrames(animFrams,0.5f);
    	animation->setDelayPerUnit(0.2f);
    	CCAnimate* animate=CCAnimate::create(animation);
    	shrew->runAction(CCRepeatForever::create(animate));


    代码参考了这位作者 的文章,并针对2.0版引擎做了一点修改主要是文章中用的数组CCMutableArray改为了CCArray等。把代码写下来备忘。同时感谢原作者。

  • 相关阅读:
    .net反编译原理
    科学使用Log4View2
    头条一面竟然问我Maven?
    SpringCloud Netflix(一) :微服务架构
    Linux环境安装Docker
    Quartz定时任务
    Jedis连接外部Redis
    宝塔phpmyadmin打不开的可能问题及解决方法
    文件上传 Window & Linux
    SpringBoot登录判断
  • 原文地址:https://www.cnblogs.com/zhong-dev/p/4044617.html
Copyright © 2011-2022 走看看