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

  • 相关阅读:
    jQuery serialize()方法无法获取表单数据
    gorm 零值不更新问题
    SpringCloud Nacos使用和配置,SpringCloud Nacos 服务注册中心配置使用
    Nacos longPolling error,Nacos1.4.1服务配置文件更新一次后报错
    Windows Mysql5.7安装和配置,Windows 安装多个Mysql
    SpringCloud Gateway使用和配置,SpringCloud Gateway predicates详细配置
    Windows RabbitMQ_3.8 安装和配置,Windows erlang下载
    SpringCloud Hystrix dashboard2.2.7使用和配置,SpringCloud Hystrix dashboard服务监控
    SpringCloud Hystrix使用和配置,SpringCloud Hystrix服务熔断降级
    SpringCloud OpenFeign使用和配置,Java OpenFeign 使用教程
  • 原文地址:https://www.cnblogs.com/wodehao0808/p/3642320.html
Copyright © 2011-2022 走看看