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

今晚收获不少,加油加油加加加!!!

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值