最近項(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]);
}