代码拉取完成,页面将自动刷新
#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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。