大佬教程收集整理的这篇文章主要介绍了cocos2dx 3D战斗类游戏制作:【一】——数据库之二,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
上一篇,做了数据库结构设计,这篇,简单说说在游戏中依靠数据库,调用产生一个场景。
很简单,加入一个LoadScene(),在Cocos载入一个Scene的时候,调用LoadScene()来载入场景所需的一切即可。
void GhostBox::LoadScene() { //根据scene_id查询场景数据,并初始化场景 map<String,String> m; vector<map<String,String>> vect = DBHelper::GetTable("SELEct * from scene where scene_id=1"); //log("sqlite-->GetTable returns %d row",vect.size()); m = vect[0]; //设定场景模型 if (m["scene_3dm"] != ""&&m["scene_3dt"] != ""&&m["scene_3ds"] != "") { std::string filename = m["scene_3dm"].c_str(); auto sprite = Sprite3D::create(fileName); sprite->setTexture(m["scene_3dt"].c_str()); sprite->setScale(atof(m["scene_3ds"].c_str())); _layer3D->addChild(spritE); } //设定场景光照 if (m["lighta_r"] != ""&&m["lighta_g"] != ""&&m["lighta_b"] != "") { //散射光,颜色 _ambientLight = AmbientLight::create(Color3B(atoi(m["lighta_r"].c_str()),atoi(m["lighta_g"].c_str()),atoi(m["lighta_b"].c_str()))); _ambientLight->retain(); _ambientLight->setEnabled(true); addChild(_ambientLight); _ambientLight->setCameraMask(2); } if (m["lightd_r"] != ""&&m["lightd_g"] != ""&&m["lightd_b"] != "") { //方向光源,方向/颜色 _directionalLight = DirectionLight::create(Vec3(0.0f,0.0f,-1.0f),Color3B(atoi(m["lightd_r"].c_str()),atoi(m["lightd_g"].c_str()),atoi(m["lightd_b"].c_str()))); _directionalLight->retain(); _directionalLight->setEnabled(true); addChild(_directionalLight); _directionalLight->setCameraMask(2); } //背景音乐 if (m["scene_bgm"] != ""){ // preload BACkground music and effect //SimpleAudioENGIne::geTinstance()->preloadBACkgroundMusic(m["scene_bgm"].c_str()); //SimpleAudioENGIne::geTinstance()->setBACkgroundMusicVolume(0.1); //SimpleAudioENGIne::geTinstance()->playBACkgroundMusic(m["scene_bgm"].c_str(),truE); } }
在这里,使用的数据库是sqlite,数据库的查询用到网上随处可见的DBHelper类。自己去下载吧。
对应上面的代码,贴一下Scene数据库相关的记录,一目了然,呵呵
LoadScene之外,当然还要LoadBB,LoadBoss,Load一堆这个场景需要的东西,方法掌握了,其实也就很简单了,从数据库去查,在程序里面画出来就是了呗,对吧。
也许有人说——为什么要用数据库呢?
以上是大佬教程为你收集整理的cocos2dx 3D战斗类游戏制作:【一】——数据库之二全部内容,希望文章能够帮你解决cocos2dx 3D战斗类游戏制作:【一】——数据库之二所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。