iOS使用cocos2dx實(shí)現(xiàn)直播中的送禮物動(dòng)畫

最近項(xiàng)目中要用到cocos2dx實(shí)現(xiàn)送禮物的功能,因?yàn)橹皼]有接觸過,所以還是走了不少?gòu)澛贰,F(xiàn)在分享一下最終集成的過程,其實(shí)很簡(jiǎn)單哦。

(本文中使用的框架是從深山老宅中挖出來的,想要使用官網(wǎng)等版本的請(qǐng)?zhí)^。)


1.創(chuàng)建項(xiàng)目,導(dǎo)入所需要的依賴庫(kù)。


將文件"cocos_include"放在工程目錄下,不要直接拖進(jìn)xcode里。兩個(gè).a文件可以直接導(dǎo)入。

Build Setting --> Head Search Path 中添加下列路徑


其他需要配置的地方。

執(zhí)行動(dòng)畫的代碼是這樣的


@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

[selfstartCoCo];

}

// 先運(yùn)行cocos2d

- (void)startCoCo{

cocos2d::CCApplication::sharedApplication()->run();

}

// 展示動(dòng)畫的view

- (EAGLView*)glView{

if(_glView==nil) {

_glView= [EAGLViewviewWithFrame: [[UIScreenmainScreen]bounds] pixelFormat:kEAGLColorFormatRGBA8 depthFormat:GL_DEPTH24_STENCIL8_OES preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0];

glClearColor(0,0,0,0);

_glView.opaque=NO;

_glView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

[_glView setBackgroundColor:[UIColorclearColor]];

}

return_glView;

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event{

[selfstarAnimation];

}

- (void)starAnimation{

cocos2d::CCDirector::sharedDirector()->startAnimation();

cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->removeSpriteFrames();

cocos2d::CCTextureCache::sharedTextureCache()->removeAllTextures();

cocos2d::CCAnimationCache::sharedAnimationCache()->removeAnimationByName("gift_10005");

[self.viewaddSubview:self.glView];

[selfshowGiftFlash:@"/Users/***/Desktop/cocos2dx/Cocos2dBumeng/Cocos2dBumeng/10009.plist"name:@"10009"];

}

-(void)showGiftFlash:(NSString*)plist name:(NSString*)name{

NSMutableDictionary*data = [[NSMutableDictionaryalloc]initWithContentsOfFile:plist];

NSArray*arr=[dataobjectForKey:@"frames"];

NSMutableDictionary*param=[NSMutableDictionarydictionary];

[paramsetObject:plistforKey:@"plistName"];

[paramsetObject:[NSStringstringWithFormat:@"%@00",name]forKey:@"imageName"];

[paramsetObject:[NSNumbernumberWithInteger:[arrcount]]forKey:@"imageNum"];

[paramsetObject:[NSNumbernumberWithInt:300]forKey:@"posX"];

[paramsetObject:[NSNumbernumberWithInt:300]forKey:@"posY"];

[paramsetObject:[NSNumbernumberWithFloat:0.1]forKey:@"delay"];

[paramsetObject:[NSNumbernumberWithFloat:0.2]forKey:@"delaydismiss"];

[paramsetObject:[NSNumbernumberWithFloat:1.2]forKey:@"ratio"];

GameScene::playGame(0, [[selfDataTOjsonString:param]UTF8String]);

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容