zoukankan      html  css  js  c++  java
  • cocos2d-x之CCMotionStreak类——2013-08-25 16

    在游戏的实现过程中,有时会需要在某个游戏对象上的运动轨迹上实现渐隐效果。这种感觉就好像是类似飞机拉线的拖尾巴,在视觉上感觉很好,比如子弹的运动轨迹等,如果不借助引擎的帮助,这种效果往往需要通过大量的图片来实现。而Cocos2D-x提供了一种内置的拖动渐隐效果类CCMotionStreak来帮助我们实现这个效果。它是CCNode类的子类,继承关系如图3-34所示。

    CCMotionStreak类的常用函数如表3-22所示。

    表3-22 CCMotionStreak类的常用函数

    streak = CCMotionStreak::create(1, 3, 64, ccc3(255,0,0), "streak.png");
        //fade:消隐动画时长,minSeg:拖尾条带相邻顶点间的最小距离,stroke:拖尾条带的宽度,color:顶点颜色值,texture:参五为所使用的纹理图片
        addChild(streak);       
        streak->setPosition(ccp(500, 200) ); 
    当你运行如下代码的时候,你会发现什么都没有。这就对了。既然是拖动渐隐,那就需要有拖动。

    以下是我写的一个小demo。拖动图片会出现拖尾效果。

    bool MenuLayer::init() {
        if (!CCLayerColor::initWithColor(ccc4(255,255,255,255))) {
            return false;
        }
        // 创建拖尾效果并放入到当前层下。  
        streak = CCMotionStreak::create(1, 1, 40, ccWHITE, "CloseNormal.png");
        //fade:消隐动画时长,minSeg:拖尾条带相邻顶点间的最小距离,stroke:拖尾条带的宽度,color:顶点颜色值,texture:参五为所使用的纹理图片
        addChild(streak);       
        streak->setPosition(ccp(500, 200) );   
        streak->setOpacity(0.52);
        this->setTouchEnabled(true);
    
        ball=CCSprite::create("CloseNormal.png");
        ball->setPosition(ccp(_winsize.width/2,_winsize.height/2));
        addChild(ball);
    
        return true;
    }
    
    void MenuLayer::registerWithTouchDispatcher(){
        CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);
    }
    
    bool MenuLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){
        CCPoint location=pTouch->getLocationInView();
        location=CCDirector::sharedDirector()->convertToGL(location);
        ball->setPosition(location);
        return true;
    }
    
    void MenuLayer::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent){
        CCLog("Move");
        CCPoint location=pTouch->getLocationInView();
        location=CCDirector::sharedDirector()->convertToGL(location);
        ball->setPosition(location);
        streak->setPosition(ccp(ball->getPositionX(),ball->getPositionY()));
    }
  • 相关阅读:
    【咖啡の设备】便携式冰滴壶——Dripo 使用体验 Experience Report of Ice Drip Coffee Maker——Dripo
    【异常记录(八)】 This operation requires IIS integrated pipeline mode.
    【异常记录(七)】MVC:从客户端中检测到有潜在危险的 Request.Form 值 的解决方法 [转] A potentially dangerous Request.Form value was detected from the client
    SQL优化:清理生产环境中已失效字段基本步骤 SQL optimization: basic steps to clean up invalid fields in production environments
    [转] sql server 跨数据库调用存储过程 SQL server calls stored procedures cross-databases
    获取lambda表达式类型,获取attributes是注意事项
    [笔记] SQL性能优化
    MSSQL 重建索引(在线重建、控制最大处理器数 、MAXDOP )
    [笔记] SQL性能优化
    [笔记] SQL性能优化
  • 原文地址:https://www.cnblogs.com/yssgyw/p/3280879.html
Copyright © 2011-2022 走看看