cocos2d播放GIF動畫類


以前項目中曾經用到過,后來因為GIF圖像的質量較差,被棄用了,把公司名字去掉分享下,根據網上資料改編的cocos2d-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

點擊下載:http://files.cnblogs.com/pure/CCSpriteGif.zip

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM