您的位置:首页 > 移动开发 > Cocos引擎

cocos2d-x 拖动效果 成功代码及截图

2013-06-05 22:14 281 查看
今晚收获不少,加油加油加加加!!!

在参照无脑码农做的小游戏的基础上做的小效果

小游戏的视频教程是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 );

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: