cocos2d 播放GIF動畫類

cocos2d 播放GIF動畫類

之前項目中曾經用到過,後來由於GIF圖像的質量較差,被棄用了,把公司名字去掉分享下,根據網上資料改編的cocos2d-iphone版的。iphone

複製代碼
//
//  CCSpriteGif.h
//
//  Created by Yuming on 13-1-23.
//  Copyright 2013年 __MyCompanyName__. All rights reserved.
//

// 本類須要導入ImageIO.framework

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import <ImageIO/ImageIO.h>

@interface CCSpriteGif : CCSprite {
    CGImageSourceRef m_gifSourceRef;                // gif動畫
    NSDictionary* m_gifProperties;                  // gif動畫屬性
    unsigned int m_loopCount;                       // gif動畫循環的總幀數
    unsigned int m_startIndex;                      // gif動畫播放開始的幀序號
    float m_playTime;                                           // gif播放總時間
}

@property (nonatomic) float playTime;

/**
 *    @brief    經過播放次數初始化GIF動畫
 *
 *    @param     path     GIF動畫的文件路徑
 *    @param     count     播放次數
 *    @param     interval     每幀播放的時間間隔
 *    @param     delay     延時delay時間後開始播放
 *    @param     startIndex     開始播放的幀索引,能夠不從第一幀放
 *
 *    @return    同init
 */
- (id)initWithGifFile:(NSString*)path andPlayCount:(unsigned int)count andInterval:(float)interval andDelay:(ccTime)delay andStartIndex:(unsigned int)startIndex;

/**
 *    @brief    經過播放時間初始化GIF動畫
 *
 *    @param     path     GIF動畫的文件路徑
 *    @param     playTime     播放動畫總時間
 *    @param     interval     每幀播放的時間間隔
 *    @param     delay     延時delay時間後開始播放
 *    @param     startIndex     開始播放的幀索引,能夠不從第一幀放
 *
 *    @return    同init
 */
- (id)initWithGifFile:(NSString*)path andPlayTime:(float)playTime andInterval:(float)interval andDelay:(ccTime)delay andStartIndex:(unsigned int)startIndex;

/**
 *    @brief    從新播放GIF動畫
 *
 *    @param     count     播放次數
 *    @param     interval     每幀播放的時間間隔
 *    @param     delay     延時delay時間後開始播放
 *    @param     startIndex     開始播放的幀索引,能夠不從第一幀放
 */
- (void)replayGifCount:(unsigned int)count andInterval:(float)interval andDelay:(ccTime)delay andStartIndex:(unsigned int)startIndex;

/**
 *    @brief    中止GIF動畫播放
 */
- (void)stopGif;

@end
相關文章
相關標籤/搜索