DELL戴尔笔记本电脑主板主板维修更换多少钱 进水

cocos2d x - Cocos2dx 3.x button sprite [C++] - Stack Overflow
Join the Stack Overflow Community
Stack Overflow is a community of 7.0 million programmers, just like you, helping each other.
J it only takes a minute:
I can't find a way to load the button image from a given .plist file instead of a plain texture.
Button::create("normal_image.png", "selected_image.png", "disabled_image.png");
button-&loadTextures("normal_image.png", "selected_image.png", "disabled_image.png");
Search for a png and not use the sprite file in the cache.
I just want to put a sprite instead of a png. The Button class is working well, and it's the best solution for my actual problem.
7,06013269
You should pass a TextureResType
Button::create("normal_image.png", "selected_image.png", "disabled_image.png", TextureResType::PLIST);
button-&loadTextures("normal_image.png", "selected_image.png", "disabled_image.png", TextureResType::PLIST);
Ok before create the button first you need to make sure that you load the plist otherwise it will not work. Ok now lets create a simple button.
Let's load the plist file.
"AppDelegate.cpp"
SpriteFrameCache::sharedSpriteFrameCache()-&addSpriteFramesWithFile("yourSprites.plist");
"PauseLayer.h"
#ifndef LEVELCHOOSER_H_
#define LEVELCHOOSER_H_
#include "cocos2d.h"
#include "Popup.h"
using namespace cocos2d;
class LevelChooser:public cocos2d::Layer
cocos2d::MenuItemSprite *pauseB
virtual bool init();
virtual void showPopup(cocos2d::Ref* pSender);
virtual void closePopup(cocos2d::Ref* pSender);
virtual void playGame(cocos2d::Ref* pSender);
virtual void playTimeGame(cocos2d::Ref* pSender);
CREATE_FUNC(LevelChooser);
#endif /* LEVELCHOOSER_H_ */
Then load the button.
in the source file.
"LevelChooser.cpp"
bool LevelChoser()
Size s = Director::getInstance-&getWinSize();
pauseButton = MenuItemSprite::create(
Sprite::createWithSpriteFrameName("ButtonPauseNormal.png"), "ButtonPauseActive.png", this,
menu_selector(LevelChooser::showPopup));
pauseButton-&setPosition(s.width/2,s.heigh/2);
void LevelChooser::showPopup(cocos2d::Ref* pSender)
//do Something
I hope you understand this well, anything just write a comment.
you can using 'CCControlButton'
// Creates a 9-slice sprite with an sprite frame name.
Scale9Sprite * img = Scale9Sprite::createWithSpriteFrame("hello.png");
Label * label = Label::create();
ControlButton * startBtn = ControlButton::create(label,img);
startBtn-&setAdjustBackgroundImage(false);
addChild(startBtn);
i think the 9-slice is best~~
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .25737
Stack Overflow works best with JavaScript enabledCocos2dX自带CCUserDefault类详解 -
- ITeye技术网站
博客分类:
在Cocos2dX中提供了自带存储类:CCUserDefault
,这里强调一点,如果你的数据量比较大,建议使用SQL存储比较适合,另外一点要注意的是,尽 可能不要在Cocos2dX中使用与平台相关的api进行开发,例如Xcode使用Cocos2dX进行开发游戏时不小心使用了iOS的控件/组件在项目 中,那么当移植到Android等平台的时候就肯定异常费劲,估计连正常运行都不可能,因为其他平台不可能正好有iOS的这些控件,即使有也肯定底层实现 不一样!换句话而言,神马功能都使用Cocos2dX api实现,尽量都向X靠拢吧,所以这里的存储我也使用X自带的CCUserDefault;至少使用Cocos2dX自带的对于跨平台这一块肯定支持的比较好啦;
言归正传,先大致介绍一下这个类的API:
PublicMemberFunctions
~CCUserDefault()
getBoolForKey (constchar*pKey,booldefaultValue=false)
Getboolvalue by key,ifthe key doesn't exist, a defaultvalue will return.
getIntegerForKey (constchar*pKey, intdefaultValue=0)
Get integer value by key, ifthe key doesn't exist, a defaultvalue will return.
getFloatForKey (constchar*pKey,floatdefaultValue=0.0f)
Getfloatvalue by key,ifthe key doesn't exist, a defaultvalue will return.
getDoubleForKey (constchar*pKey, doubledefaultValue=0.0)
Get doublevalue by key, ifthe key doesn't exist, a defaultvalue will return.
std::string
getStringForKey (constchar*pKey,conststd::string&defaultValue="")
Getstring value by key,ifthe key doesn't exist, a defaultvalue will return.
setBoolForKey (constchar*pKey, boolvalue)
Set boolvalue by key.
setIntegerForKey (constchar*pKey, intvalue)
Set integer value by key.
setFloatForKey (constchar*pKey, floatvalue)
Set floatvalue by key.
setDoubleForKey (constchar*pKey, doublevalue)
Set doublevalue by key.
setStringForKey (constchar*pKey, conststd::string &value)
Set string value by key.
Save content to xml file.
Static Public Member Functions
staticCCUserDefault *
sharedUserDefault ()
staticvoid
purgeSharedUserDefault ()
staticconststd::string &
getXMLFilePath ()
从以上可以一目了然CCUserDefault的使用和功能,哈希表结构,Key -Value,key索引Value值;
提供的存储都是些基础类型,bool,int,string,double,float,方法很容易懂:存储使用set ,获取使用get
那么最后static方法中可以看到CCUserDefault类留出了一个sharedUserDefault作为接口供开发者使用,那么大概介绍后,下面我们来写几段代码验证下:
//我们这里简单存储条数据
CCUserDefault::sharedUserDefault()-&setStringForKey("key", "himi");
CCUserDefault::sharedUserDefault()-&flush();//这里一定要提交写入哦,否则不会记录到xml中,下次启动游戏你就获取不到value了。
//这里随便定义一个string为了验证我们的存储
string str= "wahaha";
//取出我们刚存储的himi,然后赋值给str验证下;
str= CCUserDefault::sharedUserDefault()-&getStringForKey("key");
CCLog("打印str=:%s",str.c_str());
这里要注意,
CCUserDefault中有个
flush()的函数,这个用来将数据写入xml文件中,也就是说当你使用setXX的一些函数后记得提交(调用一下flush函数)
OK,下面是控制台输入的结果:
Cocos2d: cocos2d: cocos2d-1.0.1-x-0.12.0
Cocos2d: cocos2d: GL_VENDOR:
ImaginationTechnologies
Cocos2d: cocos2d: GL_RENDERER:
PowerVR SGX 543
Cocos2d: cocos2d: GL_VERSION:
OpenGL ES-CM 1.1 IMGSGX543-63.14.2
Cocos2d: cocos2d: GL_MAX_TEXTURE_SIZE:4096
Cocos2d: cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH:16
Cocos2d: cocos2d: GL supports PVRTC:YES
Cocos2d: cocos2d: GL supports BGRA8888 textures:NO
Cocos2d: cocos2d: GL supports NPOT textures:YES
Cocos2d: cocos2d: GL supports discard_framebuffer:YES
Cocos2d: cocos2d: compiled with NPOT support:NO
Cocos2d: cocos2d: compiled with VBO support inTextureAtlas:NO
Cocos2d:打印str=:himi
最后一句验证了我们的存储没问题,那么我们现在验证是否真的存在xml中了,首先停止当前运行的项目,然后删除刚才代码替换如下代码:
CCLog("打印str=:%s",CCUserDefault::sharedUserDefault()-&getStringForKey("key").c_str());
然后重新运行此项目,观察控制台打印如下:
Cocos2d: cocos2d: cocos2d-1.0.1-x-0.12.0
Cocos2d: cocos2d: GL_VENDOR:
ImaginationTechnologies
Cocos2d: cocos2d: GL_RENDERER:
PowerVR SGX 543
Cocos2d: cocos2d: GL_VERSION:
OpenGL ES-CM 1.1 IMGSGX543-63.14.2
Cocos2d: cocos2d: GL_MAX_TEXTURE_SIZE:4096
Cocos2d: cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH:16
Cocos2d: cocos2d: GL supports PVRTC:YES
Cocos2d: cocos2d: GL supports BGRA8888 textures:NO
Cocos2d: cocos2d: GL supports NPOT textures:YES
Cocos2d: cocos2d: GL supports discard_framebuffer:YES
Cocos2d: cocos2d: compiled with NPOT support:NO
Cocos2d: cocos2d: compiled with VBO support inTextureAtlas:NO
Cocos2d:打印str=:himi
通过刚才的key-&”key”,正常获取到“himi”这个字符串了,OK,监测没问题;
那么一般情况下我们会需要一个方法就是判定当前项目是否已经有存储数据的xml文件存在了,那么Himi这里说下,Cocos2dX默认源码中有这个方法,但是并没有提供给开发者使用,因为此函数被private私有了,此函数源码如下图所示:
那么既然如此Himi这里就自定义了一个检测是否已存在数据xml的函数提供大家使用:
bool isHaveSaveFile();
.cpp文件:
//当前项目是否存在存储的xml文件
bool HelloWorld::isHaveSaveFile(){
if(!CCUserDefault::sharedUserDefault()-&getBoolForKey("isHaveSaveFileXml"))
CCUserDefault::sharedUserDefault()-&setBoolForKey("isHaveSaveFileXml",true);
CCUserDefault::sharedUserDefault()-&flush();//提交
CCLog("存储文件不存在,头次开始加载游戏");
returnfalse;
CCLog("存储文件已存在");
returntrue;
备注:当存储数据的xml不存在的时候,你的第一次存储数据的时候默认会创建,路径在你的app下的documents,如下图所示:
那么这里强调一点!大家要注意setXX的函数的参数,例如以下这个函数:
setStringForKey (constchar*pKey,const std::string&value)
第一个参数是const char*类型,不是string!!!!(Himi因为这个原因浪费不少时间,悲剧阿。)
Himi当时存储写了如下代码,造成错误,如下:
CCUserDefault::sharedUserDefault()-&setStringForKey(""+823, sKey);
错误截图如下:(存储的key变成了路径。。。。《数据是Himi加密后的》)
哎,郁闷,这里Himi犯错希望童鞋们不要再范此错误,之前Himi一直想找 itoa 找个函数,但是怎么都找不到!(c++
应该存在的整形转字符串),但是Cocos2dX中没有,并且最后Himi使用了与Cocos2dX引擎中的实现itoa的源码,发现如下:
Cocos2dX自带的这个CCUserDefault并不是加密的,而是明文并且是.xml格式的,所以后续准备写一篇使用base64来进行加密的文章供大家参考;
浏览: 30895 次
来自: 南京
rowColorFunction 和setCustomColo ...你的位置: >
> 【cocos2d-x】UserDefault保存数组(ValueVector)
游戏中用到一个数组,需要保存起来,每次打开都从本地读取。但是UserDefault只支持对基础数据类型做存储(有个setDataForKey,搜了一下,只知道是保存二进制值,没有人用过),只能直接写了~
首先想到Value这个类可以进行基础数据类型的转换,例如:Value().asInt() 就可以得到123,于是就把数组改写成ValueVector(存放Value的Vector)。
写成一个单例类:
DataCenter.h
#include "cocos2d.h"
USING_NS_CC;
class DataCenter
static DataCenter *getInstance();
void setValueVectorForKey(ValueVector &vector, const char *key);
ValueVector getValueVectorByKey(const char *key);
static DataCenter *_dataC
“DataCenter.cpp”
#include "DataCenter.h"
#include "string.h"
#define splite
DataCenter * DataCenter ::_dataCenter =
DataCenter* DataCenter::getInstance()
if (! _dataCenter)
_dataCenter = new DataCenter();
return _dataC
void DataCenter::setValueVectorForKey(ValueVector &vector, const char *key)
std::string valueString = "";
for (int i = 0; i & vector.size(); i++) {
valueString = valueString + vector.at(i).asString();
if (i != vector.size() - 1) {
valueString +=
UserDefault::getInstance() -& setStringForKey(key, valueString);
ValueVector DataCenter::getValueVectorByKey(const char * key)
ValueVector valueV
std::string valueString = UserDefault::getInstance() -& getStringForKey(key);
std::string::
std::string tmp = "";
for(i = valueString.begin(); i &= valueString.end(); ++i) {
if((const char)*i != splite
&& i != valueString.end()) {
tmp += *i;
valueVector.push_back(Value(tmp));
return valueV
实现方法:
写,遍历数组,拼成一个字符串存起来,使用UserDefault保存起来
读,通过UserDefault读取字符串,把字符串分割成一个数组
本文永久地址:/5776.html本文出自
,转载时请注明出处及相应链接。
与本文相关的文章Cocos2dx笔记_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Cocos2dx笔记
上传于|0|0|文档简介
&&根据极客学院的学习路线做的笔记
阅读已结束,如果下载本文需要使用2下载券
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩13页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢&>&&>&&>&&>&cocos2dx 用户数据加密
cocos2dx 用户数据加密
上传大小:2KB
cocos2dx中用户数据加密,让USerDefault的数据不可见
综合评分:4.3(10位用户评分)
所需积分:3
下载次数:45
审核通过送C币
创建者:mfkbbdx1
创建者:daiyinglang
创建者:nigelyq
课程推荐相关知识库
上传者其他资源上传者专辑
移动开发热门标签
VIP会员动态
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
android服务器底层网络模块的设计方法
所需积分:0
剩余积分:720
您当前C币:0
可兑换下载积分:0
兑换下载分:
兑换失败,您当前C币不够,请先充值C币
消耗C币:0
你当前的下载分为234。
cocos2dx 用户数据加密
会员到期时间:
剩余下载次数:
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可奖励20下载分
被举报人:
huahua12300
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:

我要回帖

更多关于 戴尔笔记本主板维修 的文章

 

随机推荐