Skip to content

Instantly share code, notes, and snippets.

@tks2shimizu
Created January 13, 2013 17:08
Show Gist options
  • Save tks2shimizu/4525092 to your computer and use it in GitHub Desktop.
Save tks2shimizu/4525092 to your computer and use it in GitHub Desktop.
CCMotionStreakの利用
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;
using namespace CocosDenshion;
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
this->setTouchEnabled(true);
this->setTouchMode(kCCTouchesOneByOne);
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
streak = CCMotionStreak::create(2, 3, 32, ccGREEN, "streak.png");
streak->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(streak);
CCFiniteTimeAction* action = CCSequence::create(CCTintTo::create(0.2f, 255, 0, 0),
CCTintTo::create(0.2f, 0, 255, 0),
CCTintTo::create(0.2f, 0, 0, 255),
CCTintTo::create(0.2f, 0, 255, 255),
CCTintTo::create(0.2f, 255, 255, 0),
CCTintTo::create(0.2f, 255, 0, 255),
CCTintTo::create(0.2f, 255, 255, 255),
NULL);
CCActionInterval *colorAction = CCRepeatForever::create((CCActionInterval *)action);
streak->runAction(colorAction);
return true;
}
bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
return true;
}
void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
{
// タップポイント取得
CCDirector* pDirector = CCDirector::sharedDirector();
CCPoint touchPoint = pDirector->convertToGL(pTouch->getLocationInView());
// タップ位置へパーティクルを移動
streak->setPosition(touchPoint);
}
//#ifndef __HELLOWORLD_SCENE_H__
//#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::CCLayer
{
private:
cocos2d::CCMotionStreak *streak;
public:
virtual bool init();
static cocos2d::CCScene* scene();
CREATE_FUNC(HelloWorld);
virtual bool ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent);
virtual void ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent);
};
//#endif // __HELLOWORLD_SCENE_H__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment