cocosStudio使用

cocosStudio使用,第1张

概述使用cocostudio新建了一个项目,名字“Ma”,里面有两个控件,一个Button,名字“Button”。一个TextView,名字“text” 然后把导出的cocostudio项目添加到vc项目的resource中,然后是代码.h [cpp]  view plain copy #ifndef __HELLOWORLD_SCENE_H__   #define __HELLOWORLD_SCEN 使用cocostudio新建了一个项目,名字“Ma”,里面有两个控件,一个button,名字“button”。一个TextVIEw,名字“text”


然后把导出的cocostudio项目添加到vc项目的resource中,然后是代码.h




[cpp] view plain copy #ifndef__HELLOWORLD_SCENE_H__ #define__HELLOWORLD_SCENE_H__ #include"cocos2d.h" #include"cocos-ext.h" USING_NS_CC_EXT; classHelloWorld:publiccocos2d::cclayer { public: //Here'sadifference.Method'init'incocos2d-xreturnsbool,insteadofreturning'ID'incocos2d-iphone virtualboolinit(); //there'sno'ID'incpp,sowerecommandtoreturntheexactlyclasspointer staticcocos2d::CCScene*scene(); //aselectorcallback voIDmenuCloseCallback(CCObject*pSender); voIDtouchEvent(CCObject*pSender,touchEventTypetype); voIDcountrytouch(CCObject*pSender,touchEventTypetype); //implementthe"staticnode()"methodmanually UILabel*mText; UILabel*mCountryLabel; CREATE_FUNC(HelloWorld); }; #endif//__HELLOWORLD_SCENE_H__
cpp

#include"HelloWorldScene.h" usingnamespacecocos2d; CCScene*HelloWorld::scene() CCScene*scene=NulL; do { scene=CCScene::create(); CC_BREAK_IF(!scene); HelloWorld*layer=HelloWorld::create(); CC_BREAK_IF(!layer); scene->addChild(layer); }while(0); returnscene; } boolHelloWorld::init() boolbRet=false; do CC_BREAK_IF(!cclayer::init()); //创建一个画布 UILayer*ul=UILayer::create(); //把画布添加到场景中 this->addChild(ul); //创建一个文本框 mText=UILabel::create(); mText->setText("text"); mText->set@R_403_6837@name(""); mText->set@R_403_6837@Size(32); mText->setAnchorPoint(ccp(0.5f,-1)); mText->setposition(ccp(100,100)); ul->addWidget(mText); //创建一个button按钮 UIbutton*playBtn=UIbutton::create(); playBtn->settouchEnable(true); playBtn->setTag(1); playBtn->loadTextures("image/btn-play-normal.png","image/btn-play-selected.png",""); playBtn->addtouchEventListener(this,toucheventselector(HelloWorld::touchEvent)); playBtn->setposition(ccp(50,50)); ul->addWidget(playBtn); //调用UI编辑器编辑的按钮 //把UI编辑的地图添加到画布中 UIWidget*pUI=CCUIHELPER->createWidgetFromJsonfile("Ma.Json"); ul->addWidget(pUI); //获取UI上button的的控件 UIWidget*countryBtn=UIHelper::instance()->seekWidgetByname(pUI,"button"); //dynamic_cast<UIWidget*>(pUI) countryBtn->addtouchEventListener( mCountryLabel=(UILabel*)(UIHelper::instance()->seekWidgetByname(pUI,"text")); bRet=true; }while(0); returnbRet; voIDHelloWorld::menuCloseCallback(CCObject*pSender) CCDirector::sharedDirector()->end(); } voIDHelloWorld::touchEvent(CCObject*pSender,touchEventTypetype){ inttag=((UIWidget*)pSender)->getTag(); switch(tag){ case1: switch(type){ casetouch_EVENT_BEGAN: mText->setText("1"); break; casetouch_EVENT_MOVED: mText->setText("2"); break; casetouch_EVENT_ENDED: mText->setText("3"); case8: switch(type){ casetouch_EVENT_BEGAN: mCountryLabel->setText("1"); casetouch_EVENT_MOVED: mCountryLabel->setText("2"); casetouch_EVENT_ENDED: mCountryLabel->setText("3"); }; 总结

以上是内存溢出为你收集整理的cocosStudio使用全部内容,希望文章能够帮你解决cocosStudio使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1003243.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存