zoukankan      html  css  js  c++  java
  • 重载操作符

    /**

     * 重载操作 

     * add: duanxian

     * date: 2014.03.31

     */

    #ifndef ZJH_MyOperator_h

    #define ZJH_MyOperator_h

    #include "cocos2d.h"

    usingnamespacecocos2d;

    // -- operator +

    inlinecocos2d::CCPointoperator + ( constcocos2d::CCPoint& p1, constcocos2d::CCPoint& p2 ) {

        return ccp( p1.x + p2.x, p1.y + p2.y );

    }

    inlinecocos2d::CCPointoperator + ( constcocos2d::CCPoint& p1, constcocos2d::CCSize& s2 ) {

        return ccp( p1.x + s2.width, p1.y + s2.height );

    }

    inlinecocos2d::CCPointoperator + ( constcocos2d::CCSize& s1, constcocos2d::CCPoint& p2 ) {

        return ccp( s1.width + p2.x, s1.height + p2.y );

    }

    inlinecocos2d::CCPointoperator + ( constcocos2d::CCSize& s1, constcocos2d::CCSize& s2 ) {

        return ccp( s1.width + s2.width, s1.height + s2.height );

    }

    // -- operator -

    inlinecocos2d::CCPointoperator - ( constcocos2d::CCPoint& p1, constcocos2d::CCPoint& p2 ) {

        return ccp( p1.x - p2.x, p1.y - p2.y );

    }

    inlinecocos2d::CCPointoperator - ( constcocos2d::CCPoint& p1, constcocos2d::CCSize& s2 ) {

        return ccp( p1.x - s2.width, p1.y - s2.height );

    }

    inlinecocos2d::CCPointoperator - ( constcocos2d::CCSize& s1, constcocos2d::CCPoint& p2 ) {

        return ccp( s1.width - p2.x, s1.height - p2.y );

    }

    inlinecocos2d::CCPointoperator - ( constcocos2d::CCSize& s1, constcocos2d::CCSize& s2 ) {

        return ccp( s1.width - s2.width, s1.height - s2.height );

    }

    // -- operator *

    inline cocos2d::CCPoint operator * ( const cocos2d::CCPoint& p1, const float scale ) {

        return ccp( p1.x * scale, p1.y * scale );

    }

    inline cocos2d::CCPoint operator * ( const cocos2d::CCSize& s1, const float scale ) {

        return ccp( s1.width * scale, s1.height * scale );

    }

    inline cocos2d::CCPoint operator * ( const float scale, const cocos2d::CCPoint& p2 ) {

        return ccp( scale * p2.x, scale * p2.y );

    }

    inline cocos2d::CCPoint operator * ( const float scale, const cocos2d::CCSize& s2 ) {

        return ccp( scale * s2.width, scale * s2.height );

    }

    // -- operator /

    inline cocos2d::CCPoint operator / ( const cocos2d::CCPoint& p1, const float scale ) {

        return ccp( p1.x/scale, p1.y/scale );

    }

    inline cocos2d::CCPoint operator / ( const cocos2d::CCSize& s1, const float scale ) {

        return ccp( s1.width/scale, s1.height/scale );

    }

    inline cocos2d::CCPoint operator / ( const float scale, const cocos2d::CCPoint& p2 ) {

        return ccp( scale/p2.x, scale/p2.y );

    }

    inline cocos2d::CCPoint operator / ( const float scale, const cocos2d::CCSize& s2 ) {

        return ccp( scale/s2.width, scale/s2.height );

    }

    inline cocos2d::CCSpriteFrame* getMySpriteFrame( const std::string name ) {

        CCSpriteFrame* pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName( name.c_str() );

        

        if( pFrame ) {

            return pFrame;

        }

        CCLOG("spriteFrame create is fail by getMySpriteFrame(/*name*/) %s ", name.c_str() );

        

        returnNULL;

    }

    inline cocos2d::CCSprite* getMySprite( const std::string name ) {

        CCSprite* pSprite = CCSprite::createWithSpriteFrame( getMySpriteFrame( name ) );

        if( pSprite ) {

            return pSprite;

        }

        CCLOG("sprite create is fail by getMySprite(/*name*/) %s ", name.c_str() );

        returnNULL;

    }

    #endif

    转载请注明出处:http://www.cnblogs.com/wodehao0808/p/3642320.html

  • 相关阅读:
    SQL Server 2005技术内幕:查询、调整和优化2——Bookmark Lookup
    隐藏文字用图片代替方案
    检索get参素
    a:hover之后ie6要恢复原来的状态需要hover的时候改变a的状态
    暂记
    台式机搭建wifi热点
    多行文本垂直居中
    chrome上做web app开发 模拟不同的分辨率和设备
    工厂模式和构造函数
    字符串替换
  • 原文地址:https://www.cnblogs.com/wodehao0808/p/3642320.html
Copyright © 2011-2022 走看看