退出游戏,体力值恢复时间改变怎样判断 cocos creator 退出

Pages: 1/2
主题 : 请问,如何实现体力系统,隔一段时间自动恢复体力的那种!!1
级别: 新手上路
可可豆: 32 CB
威望: 32 点
在线时间: 24(时)
发自: Web Page
来源于&&分类
请问,如何实现体力系统,隔一段时间自动恢复体力的那种!!1&&&
最近开发一款游戏,想来想去想不通这一部分是如何实现的,谢谢谢谢
级别: 版主
可可豆: 2200 CB
威望: 26364 点
在线时间: 5914(时)
发自: Web Page
记录上次恢复体力时间,计算当前时间过了多久,按一定关系计算恢复多少体力
级别: 新手上路
可可豆: 32 CB
威望: 32 点
在线时间: 24(时)
发自: Web Page
可如果玩家修改系统时间的话,是不是很快就可以恢复体力了
级别: 新手上路
可可豆: 32 CB
威望: 32 点
在线时间: 24(时)
发自: Web Page
回 1楼(insul) 的帖子
可如果玩家修改系统时间的话呢,这个问题有没有方法解决,体力会恢复的很快的阿
级别: 精灵王
UID: 308160
可可豆: 2438 CB
威望: 2663 点
在线时间: 1034(时)
发自: Web Page
回 3楼(asdalun) 的帖子
用schedule定时器
世界上有10种人,一种是懂二进制的,一种是不懂二进制的
级别: 新手上路
UID: 331440
可可豆: 62 CB
威望: 46 点
在线时间: 64(时)
发自: Web Page
回 2楼(asdalun) 的帖子
用服务器的时间啊。。。。。。。。。。。
级别: 新手上路
可可豆: 32 CB
威望: 32 点
在线时间: 24(时)
发自: Web Page
回 4楼(luckyyangl) 的帖子
用schedule的话如果游戏退出了怎么办,退出游戏了以后,无法进行恢复时间的计算了
级别: 新手上路
可可豆: 32 CB
威望: 32 点
在线时间: 24(时)
发自: Web Page
回 5楼(ngnl314) 的帖子
那就只有服务器的时间可取了么,必须联网才可以游戏呗
级别: 精灵王
UID: 308160
可可豆: 2438 CB
威望: 2663 点
在线时间: 1034(时)
发自: Web Page
回 6楼(asdalun) 的帖子
嗯&&是会那样&& 我玩过一些战略类的游戏&&都有过这种修改系统时间可以作弊的问题
世界上有10种人,一种是懂二进制的,一种是不懂二进制的
级别: 版主
可可豆: 2200 CB
威望: 26364 点
在线时间: 5914(时)
发自: Web Page
服务器时间
Pages: 1/2
关注本帖(如果有新回复会站内信通知您)
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 关注CVP公众号
扫一扫 浏览移动版1616人阅读
cocos2d-x(35)
跟前面第18部分处理,问号事件一样,角色行走完毕后,还要检查停留问题是否有积分卡,如果有则增加相应的体力值
1、新建Item_strength_up类,该类用来显示角色体力回升的动画。
void Item_strength_up::addItemSpriteFrameCache()
itemSpriteFrameCache = SpriteFrameCache::getInstance();
itemSpriteFrameCache-&addSpriteFramesWithFile(&images/strength_up.plist&,&images/strength_up.png&);
memset(name, 0, 20);
for (int i=1; i&=14; i++)
sprintf(name, &strength_up_%02d.png&,i);
item_anim_vector.pushBack(itemSpriteFrameCache-&getSpriteFrameByName(name));
void Item_strength_up::setItemAnimate()
if(!AnimationCache::getInstance()-&getAnimation(&strength_up_animation&))
AnimationCache::getInstance()-&addAnimation(Animation::createWithSpriteFrames(item_anim_vector,0.1f),&strength_up_animation&);
normal_anmi = Animate::create(AnimationCache::getInstance()-&getAnimation(&strength_up_animation&));
normal_anmi-&retain();
2、在RicherGameController类的handlePropEvent方法中,添加积分卡的判断,如果停留位置有积分卡,则发送增加体力的MSG_STRENGTH_UP消息
void RicherGameController::handlePropEvent()
if(endId == GameBaseScene::strength_30_tiledID)
String * str = String::createWithFormat(&%d-%f-%f-%d&,MSG_STRENGTH_UP30_TAG,pointInMap.x,pointInMap.y,_richerPlayer-&getTag());
NotificationCenter::getInstance()-&postNotification(MSG_STRENGTH_UP,str);
if(endId == GameBaseScene::strength_50_tiledID)
String * str = String::createWithFormat(&%d-%f-%f-%d&,MSG_STRENGTH_UP50_TAG,pointInMap.x,pointInMap.y,_richerPlayer-&getTag());
NotificationCenter::getInstance()-&postNotification(MSG_STRENGTH_UP,str);
if(endId == GameBaseScene::strength_80_tiledID)
String * str = String::createWithFormat(&%d-%f-%f-%d&,MSG_STRENGTH_UP80_TAG,pointInMap.x,pointInMap.y,_richerPlayer-&getTag());
NotificationCenter::getInstance()-&postNotification(MSG_STRENGTH_UP,str);
3、GameBaseScene中继续注册增加体力值的观察以及处理代码
void GameBaseScene::registerNotificationObserver()
.............
NotificationCenter::getInstance()-&addObserver(
callfuncO_selector(GameBaseScene::receivedNotificationOMsg),
MSG_STRENGTH_UP,
receivedNotificationOMsg调用doItemStrengthUp方法,来具体处理体力值增加和体力恢复动画的播放
void GameBaseScene::receivedNotificationOMsg(Object* data)
.............
case MSG_STRENGTH_UP30_TAG:
doItemStrengthUp(MSG_STRENGTH_UP30_TAG, messageVector.at(3)-&intValue());
case MSG_STRENGTH_UP50_TAG:
doItemStrengthUp(MSG_STRENGTH_UP50_TAG, messageVector.at(3)-&intValue());
case MSG_STRENGTH_UP80_TAG:
doItemStrengthUp(MSG_STRENGTH_UP80_TAG, messageVector.at(3)-&intValue());
4、体力动画播放完毕后,调用发送消息 sendMSGDealAroundLand ,来处理角色上下左右相邻地块事件
void GameBaseScene::doItemStrengthUp(int strengthUp,int playerTag)
int strengthValue = 0;
//根据积分卡值,给strengthValue赋相应值
switch(strengthUp)
case MSG_STRENGTH_UP30_TAG:
strengthValue =30;
case MSG_STRENGTH_UP50_TAG:
strengthValue =50;
case MSG_STRENGTH_UP80_TAG:
strengthValue =80;
switch(playerTag)
case PLAYER_1_TAG:
//设置item_strength_up在角色的位置可见,播放动画,显示toast。播放完毕设置item_strength_up不可见
item_strength_up-&setVisible(true);
item_strength_up-&setPosition(player1-&getPosition()-ccp(5,0));
Sequence* action = Sequence::create(item_strength_up-&getNormal_anmi(),
CallFunc::create([this](){
item_strength_up-&setVisible(false);
item_strength_up-&runAction(action);
CocosToast::createToast(this,
String::createWithFormat(&%s %d&,LanguageString::getInstance()-&getLanguageString(STRENGTH_UP)-&getCString(),strengthValue)-&getCString(),
TOAST_SHOW_TIME,player1-&getPosition());
refreshStrengthLabel(player1,strengthValue);
scheduleOnce(schedule_selector( GameBaseScene::sendMSGDealAroundLand),3.0f);
case PLAYER_2_TAG:
.............
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:266864次
积分:3735
积分:3735
排名:第8896名
原创:78篇
转载:106篇
评论:130条
(2)(1)(1)(4)(3)(10)(16)(1)(2)(1)(2)(5)(3)(1)(3)(6)(5)(8)(8)(8)(28)(13)(12)(9)(5)(2)(5)(7)(4)(14)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'}

我要回帖

更多关于 cocos2d js 退出游戏 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信