• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

(大全)使用COCOStudio中各种资源,附有示例代码

OC/C/C++ 开心洋葱 3111次浏览 0个评论

 

(大全)使用COCOStudio中各种资源,附有示例代码
 
 
章节索引:
 
COCOStudio UI Editor :  http://www.awzsr.com/view-5487-1.html
COCOStudio Animation Editor:http://www.awzsr.com/view-5487-2.html
COCOStudio Scene Editor:http://www.awzsr.com/view-5487-3.html
cocostudio 示例代码: http://www.awzsr.com/view-5487-4.html
 
 
COCOStudio UI Editor:
 
先把项目导出的json和资源文件放到TestGame项目的Resource目录中
 
 
 
1. 在HelloWorldScene.cpp顶部添加引用
#include "cocos-ext.h"
using namespace cocos2d::extension;
USING_NS_CC;
 
 
 
2. 创建一个UILayer层
UILayer* ul = UILayer::create();
this->addChild(ul);
ul->addWidget(CCUIHELPER->createWidgetFromJsonFile("文件名.json"));
 
 
 
3. 绑定UILayer层上控件的事件
tbOk = dynamic_cast<UITextButton*>(ul->getWidgetByName("tbOk"));
tbOk->addReleaseEvent(this, coco_releaseselector(HelloWorld::tbOkCallback));
 
 
 
增加回调函数:
void HelloWorld::tbOkCallback(cocos2d::CCObject *pSender) {
//获取文本框值,并打印
UITextField* tfOldPwd = dynamic_cast<UITextField*>(ul->getWidgetByName("tfOldPwd"));
CCLog(tfOldPwd->getStringValue());
}
 
 
#p#副标题#e#
 
 
COCOStudio Animation Editor:
 
先把项目导出的json和资源文件放到TestGame项目的Resource目录中
 
 
 
1. 文件头添加引用(同上)
 
 
 
2. 使用示例:
 
 
// 首先读取png,plist和ExportJson/json文件
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("ActionEditor/Cowboy0.png", "ActionEditor/Cowboy0.plist", "ActionEditor/Cowboy.ExportJson");
 
 
//然后创建armature类,并将进行初始化
CCArmature *armature = CCArmature::create("Cowboy");
 
 
//然后选择播放动画0,并进行缩放和位置设置
armature->getAnimation()->playByIndex(0);
 
 
//该模板中共制作了三个动画,你可以将索引修改为0/1/2中的任意值来查看不同效果
armature->setScale(0.5f);
armature->setPosition(ccp(visibleSize.width * 0.5, visibleSize.height * 0.5));
 
 
//最后将armature添加到场景中
this->addChild(armature,2);
 
 
 
#p#副标题#e#
 
 
COCOStudio Scene Editor:
 
先把项目导出的json和资源文件放到TestGame项目的Resource目录中
 
 
 
1. 文件头添加引用(同上)
 
2. 使用示例:
找到void HelloWorld::menuCloseCallback(CCObject* pSender)这个方法,并输入下面代码:
 
 
 
//创建一个新的场景
CCScene* newscene = CCScene::create();
 
 
//从CocoStudio场景编辑器生成的数据生成根节点
CCNode* pNode = CCJsonReader::sharedJsonReader()->createNodeWithJsonFile("SceneEditorTest/SceneEditorTest.json");
 
 
 
//播放背景音乐
CCComAudio* pAudio = (CCComAudio*)(pNode->getComponent("Audio"));
pAudio->playBackgroundMusic(pAudio->getFile(), pAudio->getIsLoop());
 
 
//给蝴蝶鱼配置动画
CCComRender* pFishRender = (CCComRender*)(pNode->getChildByTag(10010)->getComponent( "butterFlyFish"));
CCArmature* pButterFlyFish= (CCArmature*)(pFishRender->getRender());
pButterFlyFish->getAnimation()->playByIndex(0);
newscene->addChild(pNode, 0, 1);
 
 
//切换到新的场景
CCDirector::sharedDirector()->replaceScene(newscene);
 
 
 
3. 场景切换效果:
CCScene *s = SecondPage::scene();
CCDirector::sharedDirector()->setDepthTest(true);
CCTransitionScene *transition = CCTransitionPageTurn::create(3.0f, s, false);
 
 
#p#副标题#e#
 
 
cocostudio 示例代码:
 
GameScene.h
 
#pragma once
#include "cocos2d.h"
#include "f:\yt\game\cocos2d-x-2.2.0\cocos2dx\layers_scenes_transitions_nodes\cclayer.h"
#include "cocos-ext.h"
USING_NS_CC;
USING_NS_CC_EXT;

class GameScene :
	public CCLayer
{
public:
	GameScene(void);
	~GameScene(void);

	static CCScene*  scene();

	virtual void registerWithTouchDispatcher();
	virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);

	CCNode* pScene;
	
	void update(float dt);

	virtual bool init();

	CREATE_FUNC(GameScene);

};

 

GameScene.cpp

#include "GameScene.h"
#include "SimpleAudioEngine.h"

using namespace CocosDenshion;

GameScene::GameScene(void)
{
	this->pScene = NULL;
}


GameScene::~GameScene(void)
{
}

CCScene* GameScene::scene()
{
	
	CCLayer* newLayer = GameScene::create();

	CCScene* newscene = CCScene::create();
	newscene->addChild(newLayer,0,10);
	

	
	return newscene;
}

bool GameScene::init()
{
	if(!CCLayer::init()){
		return false;
	}

	setTouchEnabled(true);
	
	CCNode* sceneNode = CCSSceneReader::sharedSceneReader()->createNodeWithSceneFile("FightScene.json");

	this->pScene = sceneNode;

	//CCComRender *pAudioRender = (CCComRender*)this->pScene->getComponent("CCBackgroundAudio");
	//CCComAudio *pAudio = (CCComAudio*)(pAudioRender->getNode());
	//pAudio->stopBackgroundMusic();

	CCComponent* pComponent=  sceneNode->getComponent("Audio");
	CCComAudio* pAudio = (CCComAudio*)pComponent;
	
	pAudio->stopBackgroundMusic(true);


	//CCObject* pObj = NULL;
	//CCARRAY_FOREACH(sceneNode->getChildren(),pObj)
	//{
		//CCNode *pNode = (CCNode *)pObj;
		//CCLog("(%d)",pNode->getTag());
	//}



	CCComRender *pHeroRender = (CCComRender*)this->pScene->getChildByTag(10005)->getComponent("CCArmature");
	CCArmature* hero = (CCArmature *)(pHeroRender->getNode());
	hero->getAnimation()->play("loading");

	this->addChild(sceneNode,0,10);

	this->scheduleUpdate();

	return true;
}

void GameScene::registerWithTouchDispatcher()
{
	CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);
}

bool GameScene::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
	CCComRender *pHeroRender = (CCComRender*)this->pScene->getChildByTag(10005)->getComponent("CCArmature");
	CCArmature* hero = (CCArmature *)(pHeroRender->getNode());
	hero->getAnimation()->play("run");

	return true;
}

void GameScene::update(float dt)
{
	//CCLog("%f",dt);
}

 

 


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明(大全)使用COCOStudio中各种资源,附有示例代码
喜欢 (0)

您必须 登录 才能发表评论!

加载中……