Skip to content

Instantly share code, notes, and snippets.

View syuhari's full-sized avatar

Akihiro Matsuura syuhari

View GitHub Profile
@syuhari
syuhari / gist:4fab863c37da595f049c
Created May 17, 2015 20:55
string 文字列の中にある指定の文字列を繰り返し置換する
std::string replaceString(std::string string1, std::string string2, std::string string3)
{
std::string::size_type pos(string1.find(string2));
while(pos!=std::string::npos) {
string1.replace(pos, string2.length(), string3);
pos = string1.find(string2, pos + string3.length());
}
return string1;
}
@syuhari
syuhari / cocos command in post-action
Created March 22, 2014 22:16
Run cocos command in post action on Xcode
export ANT_ROOT=/usr/local/bin
export NDK_ROOT=/path/to/android-ndk
export ANDROID_SDK_ROOT=/path/to/android-sdk
export COCOS_CONSOLE_ROOT=/path/to/cocos2d-x/tools/cocos2d-console/bin
$COCOS_CONSOLE_ROOT/cocos run -s $SRCROOT/../ -p android
@syuhari
syuhari / gist:6442522
Last active December 3, 2018 02:18
Pixel Perfect Collision
bool HelloWorld::areSpritesColliding(cocos2d::CCSprite *spr1, cocos2d::CCSprite *spr2, bool pp) {
bool isColliding = false;
CCRect intersection;
CCRect r1 = spr1->boundingBox();
CCRect r2 = spr2->boundingBox();
// Look for simple bounding box collision
if (r1.intersectsRect(r2)) {
@syuhari
syuhari / gist:6345552
Created August 26, 2013 19:26
resolved a black screen for cocos2d-x ver.2.1.4 as entering foreground after tapping the power button
diff --git a/cocos2dx/platform/CCFileUtils.cpp b/cocos2dx/platform/CCFileUtils.cpp
index ba5b497..0faafa7 100755
--- a/cocos2dx/platform/CCFileUtils.cpp
+++ b/cocos2dx/platform/CCFileUtils.cpp
@@ -533,6 +533,7 @@ const char* CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
void CCFileUtils::setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder)
{
bool bExistDefault = false;
+ m_fullPathCache.clear();
m_searchResolutionsOrderArray.clear();
@syuhari
syuhari / gist:5425221
Created April 20, 2013 08:17
CCScale9Sprite sample
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCRect spriteRect = CCRectMake(0, 0, 70, 70);
CCRect capInsents = CCRectMake(6, 6, 58, 58);
CCScale9Sprite* backgroundSprite = CCScale9Sprite::create("9x9.png", spriteRect, capInsents);
CCLabelTTF* label = CCLabelTTF::create("ボタン1", "Arial", 30);
CCControlButton* button = CCControlButton::create(label, backgroundSprite);
button->setPreferredSize(CCSizeMake(200, 60));
button->setPosition(ccp(50+button->getContentSize().width/2, size.height/2+button->getContentSize().height));
@syuhari
syuhari / ModalLayer.cpp
Last active May 15, 2016 11:49
A modal layer of cocos2d-x
#include "ModalLayer.h"
using namespace cocos2d;
bool ModalLayer::init()
{
if ( !CCLayer::init() )
{
return false;
}
#include "CCTestLayer.h"
USING_NS_CC;
USING_NS_CC_EXT;
SEL_MenuHandler CCTestLayer::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName)
{
CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "menuTapped", CCTestLayer::menuTapped);
return NULL;
}
@syuhari
syuhari / gist:4705588
Created February 4, 2013 08:18
How to use CocosBuilder (Custom Class)
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
ccNodeLoaderLibrary->registerCCNodeLoader("CCTestLayer", TestBuilderLoader::loader());
CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary);
CCNode* node = ccbReader->readNodeGraphFromFile("CCTestLayer.ccbi");
CCScene * scene = CCScene::create();
if(node != NULL) {
scene->addChild(node);
}
ccbReader->release();
CCDirector::sharedDirector()->runWithScene(scene);
@syuhari
syuhari / gist:4705552
Created February 4, 2013 08:08
How to use CocosBuilder for cocos2dx
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary);
CCNode* node = ccbReader->readNodeGraphFromFile("CCTestLayer.ccbi");
CCScene * scene = CCScene::create();
if(node != NULL) {
scene->addChild(node);
}
ccbReader->release();
CCDirector::sharedDirector(->runWithScene(scene);
@syuhari
syuhari / gist:4671122
Created January 30, 2013 06:10
Cocos2d-x CCProgressTimer
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite* sprite = CCSprite::create("Icon-72.png");
CCProgressTimer* timer = CCProgressTimer::create(sprite);