Skip to content

Instantly share code, notes, and snippets.

View syuhari's full-sized avatar

Akihiro Matsuura syuhari

View GitHub Profile
@syuhari
syuhari / CardFlip
Created October 13, 2012 21:50
flip card for cocos2d-x
void Card::flipAction() {
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSprite* card = CCSprite::spriteWithFile("card_face.png");
card->setPosition(ccp(winSize.width/2, winSize.height/2));
this->addChild(card, CARD_FACE_TAG, CARD_FACE_TAG);
card->setVisible(false);
CCSprite* card2 = CCSprite::spriteWithFile("card.png");
card2->setPosition(card->getPosition());
@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);
@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: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);
#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 / 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;
}
@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 / 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: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 / 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