iOS使用cocos2dx实现直播中的送礼物动画

2018-08-30  本文已影响236人  小小小龙包

最近项目中要用到cocos2dx实现送礼物的功能,因为之前没有接触过,所以还是走了不少弯路。现在分享一下最终集成的过程,其实很简单哦。

(本文中使用的框架是从深山老宅中挖出来的,想要使用官网等版本的请跳过。)

1.创建项目,导入所需要的依赖库。

将文件"cocos_include"放在工程目录下,不要直接拖进xcode里。两个.a文件可以直接导入。

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

其他需要配置的地方。

执行动画的代码是这样的

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

[selfstartCoCo];

}

// 先运行cocos2d

- (void)startCoCo{

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

}

// 展示动画的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]);

}

上一篇下一篇

猜你喜欢

热点阅读