深秋

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

使用VS类向导添加ScreenAdapter,在Num2048项目上右键选择“添加”—>“类”,然后将生成的两个文件拖放到Classes文件夹中

                                  image                                                   image

在头文件中声明几个静态方法如下:

#ifndef __ScreenAdapter_H__
#define __ScreenAdapter_H__

#include "cocos2d.h"

class ScreenAdapter
{
public:
    /*ScreenAdapter(void);
    ~ScreenAdapter(void);*/
    static int GetFontSize(int number);
    static int GetDefaultFontSize();
    static cocos2d::ccColor3B GetColor(int number);
    static const char* GetString(int number);
};

#endif

最后在ScreenAdapter.cpp文件中定义方法

#include "ScreenAdapter.h"

//
//ScreenAdapter::ScreenAdapter(void)
//{
//}
//
//
//ScreenAdapter::~ScreenAdapter(void)
//{
//}

//默认字体大小,这个还需要修改
int ScreenAdapter::GetDefaultFontSize(){
    return 40;
}
//根据数值获取字体大小
int ScreenAdapter::GetFontSize(int number)
{
    int fontSize = 0;
    if (number >= 0) 
        fontSize = 100;
    if (number >= 16) 
        fontSize = 90;
    if(number >= 128)
        fontSize = 60;
    if(number >= 1024)
        fontSize = 40;

    return fontSize;
 }
//根据数值获取背景颜色
cocos2d::ccColor3B ScreenAdapter::GetColor(int number){

    if(number == 0)
        return cocos2d::ccc3(200,190,180);    
    if (number == 2) 
        return cocos2d::ccc3(240,230,220);
    if (number == 4) 
        return cocos2d::ccc3(240,220,200); 
    if (number == 8) 
        return cocos2d::ccc3(240,180,120);
    if (number == 16) 
        return cocos2d::ccc3(240,140,90);  
    if (number == 32) 
        return cocos2d::ccc3(240,120,90);
    if (number == 64) 
        return cocos2d::ccc3(240,90,60);  
    if (number == 128) 
        return cocos2d::ccc3(240,90,60);
    if (number == 256) 
        return cocos2d::ccc3(240,200,70);
    if (number == 512) 
        return cocos2d::ccc3(240,200,70);
    if (number == 1024)
        return cocos2d::ccc3(0,130,0);
    if (number == 2048)
        return cocos2d::ccc3(0,130,0);
}
//获取数值的字符串
const char* ScreenAdapter::GetString(int number)
{
    if(number>0)
        return cocos2d::CCString::createWithFormat("%i",number)->getCString();
    else
        return "";
}
posted on 2014-06-17 23:26  深秋  阅读(369)  评论(0编辑  收藏  举报