Home Database Mysql Tutorial Cocos2d-x动画工具类

Cocos2d-x动画工具类

Jun 07, 2016 pm 03:24 PM
for animation tool Purpose

1.此工具类的目的是为了方便执行动画,使用TexturePackerGUI工具可以导出plist文件和png图片,这里我示例图片叫bxjg.plist和bxjg.png //////////////////////////////////////.h文件 #ifndef _AnimateUtil_H_ #define _AnimateUtil_H_ #include cocos2d.h us

1.此工具类的目的是为了方便执行动画,使用TexturePackerGUI工具可以导出plist文件和png图片,这里我示例图片叫bxjg.plist和bxjg.png

//////////////////////////////////////.h文件

#ifndef _AnimateUtil_H_

#define _AnimateUtil_H_
#include "cocos2d.h"
using namespace cocos2d;
using namespace std;
class AnimateUtil//动画工具类
{
public:
//根据文件名字前缀创建动画对象                         名称   播放的间隔    是否循环播放   
static Animation * createWithSingleFrameName(const char * name, float delay, int Loops);
//根据文件名字前缀创建动画对象,指定动画图片数量        名称    图片数量  播放的间隔  是否循环播放 
static Animation * createWithFrameNameAndNum(const char * name, int num, float delay, int Loops);
};

#endif

/////////////////////////////////.cpp文件

#include "AnimateUtil.h"


Animation * AnimateUtil::createWithSingleFrameName(const char * name, float delay, int Loops)
{
/*将图片加载到精灵帧缓冲池*/
SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
Vector frameVec;
SpriteFrame * frame = NULL;
int index = 1;//小图片数量
do 
{
//从SpriteFrame缓冲池获取SpriteFrame对象
frame = frameCache->getSpriteFrameByName(StringUtils::format("%s%d.png", name, index++));
//不断获取spriteFrame对象,直到获取的值为NULL
if (frame == NULL)
{
break;
}
frameVec.pushBack(frame);
} while (true);
//使用SpiteFrame列表创建动画对象
Animation * animation = Animation::createWithSpriteFrames(frameVec);
animation->setLoops(Loops);//设置是否循环
animation->setRestoreOriginalFrame(true);
animation->setDelayPerUnit(delay);//设置动画间隙
return animation;
}


Animation * AnimateUtil::createWithFrameNameAndNum(const char * name, int num, float delay, int Loops)
{
SpriteFrameCache * frameCache = SpriteFrameCache::getInstance();


SpriteFrame * frame = NULL;
Vector frameVec;
int index = 1;
for (int  i = 1; i {
frame = frameCache->getSpriteFrameByName(StringUtils::format("%s%d.png", name, index++));
if (frame ==NULL)
{
break;
}
frameVec.pushBack(frame);
}
Animation * animation = Animation::createWithSpriteFrames(frameVec);
animation->setLoops(Loops);
animation->setRestoreOriginalFrame(true);
animation->setDelayPerUnit(delay);
return animation;
}

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1672
14
PHP Tutorial
1277
29
C# Tutorial
1257
24
How to register in the ok exchange in China? ok trading platform registration and use guide for beginners in mainland China How to register in the ok exchange in China? ok trading platform registration and use guide for beginners in mainland China May 08, 2025 pm 10:51 PM

In the cryptocurrency market, choosing a reliable trading platform is crucial. As a world-renowned digital asset exchange, the OK trading platform has attracted a large number of novice users in mainland China. This guide will introduce in detail how to register and use it on the OK trading platform to help novice users get started quickly.

Binance binance web version entrance Binance binance exchange web version directly enter Binance binance web version entrance Binance binance exchange web version directly enter May 08, 2025 pm 11:03 PM

The world's leading cryptocurrency trading platform is famous for its efficient, secure and diverse trading services. Whether you are an experienced trader or a newbie into the cryptocurrency market, Binance has the tools and resources you need. Through Binance web version, users can easily access the trading platform without downloading any applications and conduct trading operations directly through the browser. This article will introduce in detail how to enter the Binance Binance Exchange web version and provide some practical trading tips and precautions.

Yiou official website entrance Yiou exchange Apple entrance official entry Yiou official website entrance Yiou exchange Apple entrance official entry May 08, 2025 pm 11:12 PM

A world-renowned digital currency trading platform, established in 2014, is committed to providing users with safe and convenient digital asset trading services. As an international exchange, Yiou supports the transaction of a variety of mainstream and niche digital currencies, attracting users from all over the world. Whether newbies or experienced traders, you can find trading tools and services that suit you on the Yiou platform.

How to enter the bull market in May 2025? Recommended on entry exchanges How to enter the bull market in May 2025? Recommended on entry exchanges May 12, 2025 pm 08:51 PM

Recommended exchanges for bull market in May 2025: 1. Binance; 2. OKX; 3. Huobi; 4. gate.io; 5. Sesame Open Door and other exchanges. The above exchanges are safe and reliable, and support a variety of currencies. This article provides detailed download portal addresses.

Recommended for Bull Market Exchange in 2025 Recommended for Bull Market Exchange in 2025 May 12, 2025 pm 08:45 PM

Recommended exchanges for bull market in May 2025: 1. Binance; 2. OKX; 3. Huobi; 4. gate.io; 5. Sesame Open Door and other exchanges. The above exchanges are safe and reliable, and support a variety of currencies. This article provides detailed download portal addresses.

The latest links for Ouyi okx platform official latest links The latest links for Ouyi okx platform official latest links May 08, 2025 pm 10:57 PM

As the world's leading digital asset trading platform, it has attracted a large number of investors and traders with its efficient, secure and user-friendly experience. Whether you are a first-time cryptocurrency market or an experienced trading expert, Ouyi OKX provides a wealth of trading tools and services to meet the needs of users at different levels. Recently, Ouyi OKX released the latest official link to ensure that users can access the platform safely and conveniently, conduct transactions and asset management.

How to set, get and delete WordPress cookies (like a professional) How to set, get and delete WordPress cookies (like a professional) May 12, 2025 pm 08:57 PM

Do you want to know how to use cookies on your WordPress website? Cookies are useful tools for storing temporary information in users’ browsers. You can use this information to enhance the user experience through personalization and behavioral targeting. In this ultimate guide, we will show you how to set, get, and delete WordPresscookies like a professional. Note: This is an advanced tutorial. It requires you to be proficient in HTML, CSS, WordPress websites and PHP. What are cookies? Cookies are created and stored when users visit websites.

How to Fix WordPress 429 Too Many Request Errors How to Fix WordPress 429 Too Many Request Errors May 12, 2025 pm 08:54 PM

Do you see the "429 too many requests" error on your WordPress website? This error message means that the user is sending too many HTTP requests to the server of your website. This error can be very frustrating because it is difficult to find out what causes the error. In this article, we will show you how to easily fix the "WordPress429TooManyRequests" error. What causes too many requests for WordPress429? The most common cause of the "429TooManyRequests" error is that the user, bot, or script attempts to go to the website

See all articles