2016年5月31日 星期二

0531 更換ICON

https://cocosgamestory.wordpress.com/2015/08/12/%E6%9B%B4%E6%8F%9B%E6%96%B0%E7%9A%84appicon/

使用心得:
 透過網站 取得各種SIZE的ICON,在手動更換目錄下的ICON即可
(cocos2d-x 命名跟網站產生不一至!所以需要手動更換)

更換新的AppIcon

麻煩的Icon們

這幾天開始處理App Icon的事情;很久之前,當時只有iPhone3GS, 4時,更新AppIcon是一件簡單的事情;但今時今日,iphone 、ipad和Android 有多種解析度, 而且XCode 和 Eclipse 沒有提供工具給我們自動生成;唯有在網上找工具處理。

Icon Generation 工具

在這項工作中,尋找到以下工具:
大家各有各好,不過我最後還是選用了 makeappicon.com
因為她可以直接生成 Xcode 用的 Images.xcassets 和 Android 用的 drawable folders;
但她也有一個不方便的地方:她只能把生成的icon.zip 發到電郵,而不能直接下載;

搞掂了

iOS:
  • 只要把AppIcon.appiconset copy 到 proj.ios_mac/…/Images.xcassets 就可以了;
Android:
  • 把 drawable-*/ copy 到 proj.android/res;
  • 修改AndroidManifest.xml, 把
    <application android:label="@string/app_name" android:icon="@drawable/icon「>
    改為
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher「>

完成後

0528 cocos2dx[3.2](18)——屏幕截圖ScreenShot

cocos2dx[3.2](18)——屏幕截圖ScreenShot
    屏幕截圖有兩種方式:
    (1)使用RenderTexture          :這是在2.x版本時最常用的的截圖方法。
    (2)使用utils::captureScreen() :在3.2版本中新增的截圖方法。

補匆
since cocos2dx 3.x i think you should call the render() method first then call newImage() in order to get the image safely:
Director::getInstance()->getRenderer()->render();
auto img = rt->newImage();// now you can get your image without any problems!

 //don't forget to release image memory
CC_SAFE_DELETE_ARRAY(img);
【致謝】



【RenderTexture】
    RenderTexture這個動態紋理類,顧名思義就是可以動態創建紋理圖片。
    屏幕截圖主要步驟:
        > 開始截圖:render->begin();
        > 遍歷場景:scene->visit();
        > 結束截圖:render->end();
        > 保存截圖:render->saveToFile(string& filename, Image::Format format);
    其中Image::Format為圖片格式,可以保存為PNG、或JPG兩種格式。
    即:Image::Format::PNGImage::Format::JPG

1、截圖方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//
void HelloWorld::capture(Ref* sender)
{
    CCLOG("ScreenShot");
    //獲取屏幕尺寸大小
    Size winSize = CCDirector::sharedDirector()->getWinSize();
    //創建RenderTexture,紋理圖片大小為窗口大小winSize
    RenderTexture* screen = RenderTexture::create(winSize.width, winSize.height);
    //屏幕截圖
    screen->begin();            //開始抓屏
    this->getParent()->visit(); //遍歷當前場景Scene的所有子節點信息,畫入screen中
    screen->end();              //結束抓屏
    //保存截圖
    screen->saveToFile("ScreenShot.png", Image::Format::PNG); //保存為PNG格式
    //screen->saveToFile("ScreenShot.jpg", Image::Format::JPG); //保存為JPG格式
}
//

2、保存路徑
    > Win32  :保存在 Debug.win32/ 目錄下。
    > Android:保存在 /data/data/com.summer.hello/files/ScreenShot.png 。



【utils::captureScreen】
    在v3.2版本utils::captureScreen()方法被加入用於保存屏幕截圖。
    
1、定義
1
2
3
4
5
6
7
8
9
//
    // > afterCaptured :該方法將在捕捉指令後被執行。
    //                    > bool   : 捕捉屏幕截圖是否成功。
    //                    > string : 截圖存儲的路徑。
    // > filename      :截圖的名字。
    //                    > 可以只是一個文件名。  像這樣ScreenShot.png。
    //                    > 也可以是一個絕對路徑。像這樣/sdcard/ScreenShot.png。
    void captureScreen(const std::function<void(boolconst std::string&)>& afterCaptured, const std::string& filename)
//

2、截圖方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
//屏幕截圖
void HelloWorld::capture(Ref* sender)
{
    CCLOG("ScreenShot");
    utils::captureScreen(CC_CALLBACK_2(HelloWorld::afterCapture, this), "ScreenShot.png");
}
//截圖後執行afterCapture
void HelloWorld::afterCapture(bool succeed, const std::string& outputFile)
{
    if (succeed)
    {
        CCLOG("%s", outputFile.c_str());
        //顯示截圖
        Sprite* sp = Sprite::create(outputFile);
        sp->setPosition(winSize / 2);
        this->addChild(sp);
        sp->setScale(0.25); //放縮
    }
    else
    {
        CCLOG("Capture screen failed.");
    }
}
//

3、保存路徑
    filename可以只是一個文件名(保存到相對路徑):像這樣 "ScreenShot.png"
    filename也可以是一個絕對路徑                :像這樣 "/sdcard/ScreenShot.png"

cocos2dx-lua 建立滑鼠監聽

重要關鍵字  EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority      if IsPc() then --建立滑鼠監聽         local listener = cc.EventListenerMouse...