加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
xcocos_utils.h 3.79 KB
一键复制 编辑 原始数据 按行查看 历史
passker2020 提交于 2014-08-06 10:22 . +增加建创文件
#ifndef _X_COCOS_UTILS_H_
#define _X_COCOS_UTILS_H_
#include <cocos2d.h>
#include <cocos-ext.h>
#include <xlog.h>
#include <xcocos_ptr.h>
namespace zdh
{
USING_NS_CC;
USING_NS_CC_EXT;
namespace utils
{
//退出游戏
void ExitGame();
CCSprite * createSprite(const char * paramFileName, float paramX = 0.0f, float paramY = 0.0f);
CCSprite * createSpriteByFrameCache(const char * paramFrameName, float paramX = 0.0f, float paramY = 0.0f);
CCAnimate * createAnimate(const char * paramFileNameFormat, XInt paramStartCode, XInt paramEndCode, float paramDur);
//CCAnimate * pAniAction = CCAnimate::create(pAni);
template<class T>
inline void ToFullScreen(T * paramRes)
{
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
const auto stSize = paramRes->getContentSize();
paramRes->setScaleX(visibleSize.width / stSize.width);
paramRes->setScaleY(visibleSize.height / stSize.height);
}
template<class T>
inline void ToScreenMiddle(T * paramRes)
{
auto visibleSize = CCDirector::sharedDirector()->getVisibleSize();
const auto stSize = paramRes->getContentSize();
paramRes->setPosition((visibleSize.width - stSize.width)/2, (visibleSize.height - stSize.height)/2);
}
template<class LAYER>
inline CCScene * createScene()
{
CCScene *scene = CCScene::create();
LAYER *layer = LAYER::create();
scene->addChild(layer);
return scene;
}
enum EnumTransitionID
{
ETID_FADE_WHITE_TRANSITION = 1, //浅隐
ETID_FLIP_X_LEFT_OVER, //向左翻转
ETID_FLIP_X_RIGHT_OVER, //向右翻转
ETID_FLIP_Y_UP_OVER,
ETID_FLIP_Y_DOWN_OVER,
ETID_FLIP_ANGULAR_LEFT_OVER,
ETID_FLIP_ANGULAR_RIGHT_OVER,
ETID_CUSTOM_BEGIN = 10000,
ETID_CUSTOM_GAME_INFO,
};
//指定ID创建场景切换对象
/**
@param [in] paramTransitionID 切换模式的ID @see EnumTransitionID
@param [in] paramDur 切换的持续时间
@param [in] paramDestScene 目标场景
*/
CCTransitionScene * createTransition(int paramTransitionID, float paramDur, CCScene* paramDestScene);
//切换场景
/**
SCENE_NEW_LAYER 新场景类型
@param [in] paramTransitionID 切换模式的ID @see EnumTransitionID
@param [in] paramDur 切换的持续时间
*/
template<class SCENE_NEW_LAYER>
inline void TransitionScene(int paramTransitionID, float paramDur)
{
CCScene * pNew = createScene<SCENE_NEW_LAYER>();
CCTransitionScene * pTran = createTransition(paramTransitionID, paramDur, pNew);
CCDirector::sharedDirector()->replaceScene(pTran);
}
template<class SCENE_NEW_LAYER>
inline void TransitionScene(int paramTransitionID, float paramDur, SCENE_NEW_LAYER * paramScene)
{
CCTransitionScene * pTran = createTransition(paramTransitionID, paramDur, paramScene);
CCDirector::sharedDirector()->replaceScene(pTran);
}
void TransitionScene(int paramTransitionID, float paramDur, int paramSceneID);
template<class T>
inline bool isInArea(const T & paramValue, const T & paramStart, const T & paramEnd)
{
return paramValue >= paramStart && paramValue < paramEnd;
}
};
template<int N, class T>
inline XLog<N, T> & operator <<(XLog<N, T> & paramStream, const CCPoint & paramValue)
{
if (paramStream.getStreamBeginFlag())
{
paramStream.getStreamLogContent().cat_printf("{x=%lf,y=%lf}", paramValue.x, paramValue.y);
}
return paramStream;
}
template<int N, class T>
inline XLog<N, T> & operator <<(XLog<N, T> & paramStream, const CCSize & paramValue)
{
if (paramStream.getStreamBeginFlag())
{
paramStream.getStreamLogContent().cat_printf("{w=%lf,h=%lf}", paramValue.width, paramValue.height);
}
return paramStream;
}
template<class UICONTROL>
inline UICONTROL * GetControlByTag(XCocosPtr<gui::TouchGroup> & paramUI, int paramTag)
{
if (paramUI.is_null()) return nullptr;
return dynamic_cast<UICONTROL *>(paramUI->getWidgetByTag(paramTag));
}
}
#endif
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化