今晚收获不少,加油加油加加加!!!
在参照无脑码农做的小游戏的基础上做的小效果
小游戏的视频教程是http://v.youku.com/v_show/id_XNDg4OTE1Mjgw.html
我直接在gameoverscene上做修改
以是代码
头文件
#pragma once
#include "cocos2d.h"
class GameOverScene :public cocos2d::CCLayerColor
{
public:
GameOverScene(void);
~GameOverScene(void);
virtual bool init();
void gameOverDone();
CC_SYNTHESIZE_READONLY(cocos2d::CCLabelTTF*,_label,Label);
cocos2d::CCMotionStreak *streak;//新增
void ccTouchesMoved(cocos2d::CCSet *touches,cocos2d::CCEvent*event);//新增
CREATE_FUNC(GameOverScene);
};
gameoverscene.cpp
#include "GameOverScene.h"
#include "HelloWorldScene.h"
using namespace cocos2d;
GameOverScene::GameOverScene(void)
{
}
GameOverScene::~GameOverScene(void)
{
}
bool GameOverScene::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init());
CCSize winSize = CCDirector::sharedDirector()->getWinSize();//窗口大小
this->initWithColor(ccc4(255,255,255,255));//背景设置为白色
this->_label=CCLabelTTF::create("","Artial",32);
CC_BREAK_IF(!_label);//检测
_label->retain();
_label->setColor(ccc3(0,0,0));
_label->setPosition(ccp(winSize.width/2,winSize.height/2));
this->addChild(_label);
CCSize s = CCDirector::sharedDirector()->getWinSize();
setTouchEnabled(true);
streak=CCMotionStreak::create(2, 3, 32, ccGREEN,"CloseNormal.png"); //s_streak是图片名
this->addChild(streak);
streak->setPosition( ccp(s.width/2, s.height/2) );
this->runAction(
CCSequence::create(CCDelayTime::create(3),
CCCallFunc::create(this,callfunc_selector(GameOverScene::gameOverDone)),NULL));
bRet = true;
} while (0);
return bRet;
}
void GameOverScene::gameOverDone()
{
CCDirector::sharedDirector()->replaceScene(HelloWorld::scene());
}
void GameOverScene::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
CCSetIterator it = touches->begin();
CCTouch* touch = (CCTouch*)(*it);
CCPoint location=touch->getLocationInView();
location=CCDirector::sharedDirector()->convertToGL(location);
streak->setPosition( location );
}