Tuesday, May 12, 2015

cocos2d android Java 遊戲開發基礎 2 - 安裝 學習視頻筆記

資料來源: 千鋒獨家出品《Android遊戲開發基礎視頻教程》http://www.mobiletrain.org/about/news/android_video3.html

抓包來安裝:到 github 找 cocos2d android, 抓 ZhouWeikuan 的 zip 檔下來套用到 Android 已存在項目.
修改 library 和把重覆的類改名後,即可編譯。

cocos2d android Java 遊戲開發基礎1 - 介紹 學習視頻筆記

資料來源: 千鋒獨家出品《Android遊戲開發基礎視頻教程》http://www.mobiletrain.org/about/news/android_video3.html

導演--場景1--布景層1 -- 精靈1
         |                   |                   |
         |                   |                   |-- 精靈2
         |                   |-- 布景層2   |-- 精靈3
         |-- 場景2       |-- 布景層3   |-- 精靈4
                                                  |
                                                  - 精靈5

CCDirector: 導演類
CCScene: 場景類
CCLayer: 布景層
CCSprite: 精靈

Monday, December 29, 2014

使用 xmllint 處理/驗證 xml



xmllint是一個很方便的處理及驗證xml的工具,linux下只要安裝libxml2就可以使用這個命令,下面整理一些常用功能
1. --format
此參數用於格式化xml,使其具有良好的可讀性。
假設有xml(person.xml)內容如下:

<person><name>ball</name><age>30</age><sex>male</sex></person>

執行:
xmllint --format person.xml  
得到易讀的xml

    <person>  
          <name>ball</name>  
          <age>30</age>  
          <sex>male</sex>  
    </person>
    2. --noblanks
    與--format相反,有時為了節省傳輸量,我們希望去掉xml中的空白,這時我們可以使用--noblanks命令。
    假設xml(person.xml)內容如下

    <?xml version="1.0"?>  
    <person>  
      <name>ball</name>  
      <age>30</age>  
      <sex>male</sex>  
    </person>
    
      執行:
      xmllint --noblanks person.xml  
      得到去掉空白後的xml

      ball30male
      



      3.--schema
      使用scheam驗證xml文件的正確性(瞭解schema的知識請猛擊這裡
      假設有xml文件(person.xml)和scheam文件(person.xsd)文件,內容分別如下
      person.xml

      <?xml version="1.0"?>  
      <person>  
        <name>ball</name>  
        <age>30</age>  
        <sex>male</sex> 
      </person>
      

      person.xsd

      <?xml version="1.0"?>  
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">  
        <xs:element name="name" type="xs:string"/>  
        <xs:element name="age" type="xs:integer"/>  
        <xs:element name="sex">  
          <xs:simpleType>  
            <xs:restriction base="xs:string">  
              <xs:enumeration value="male"/>  
              <xs:enumeration value="female"/>  
            </xs:restriction>  
          </xs:simpleType>  
        </xs:element>  
        <xs:element name="person">  
          <xs:complexType>  
            <xs:all>  
              <xs:element ref="name"/>  
              <xs:element ref="age"/>  
              <xs:element ref="sex"/>  
            </xs:all>  
          </xs:complexType>  
        </xs:element>  
      </xs:schema>
      
      執行:

      xmllint --schema person.xsd person.xml  
      得到

        
        ball  
        30  
        male  
        
      person.xml validates 
      
      注意,默認情況下,驗證後會輸出驗證的文件內容,可以使用 --noout選項去掉此輸出,這樣我們可以只得到最後的驗證結果。
      執行

      xmllint --noout --schema person.xsd person.xml   
      得到

      person.xml validates  

      下面我們改動person.xml
      <?xml version="1.0"?>  
      <person>  
        <name>ball</name>  
        <age>not age</age>  
        <sex>test</sex>  
      </person>
      


      顯然,這份文件age字段和sex都是不符合xsd定義的。
      執行

      xmllint --noout --schema person.xsd person.xml  
      得到:

      person.xml:4: element age: Schemas validity error : Element 'age': 'not age' is not a valid value of the atomic type 'xs:integer'.  
      person.xml:5: element sex: Schemas validity error : Element 'sex': [facet 'enumeration'] The value 'test' is not an element of the set {'male', 'female'}.  
      person.xml:5: element sex: Schemas validity error : Element 'sex': 'test' is not a valid value of the local atomic type.  
      person.xml fails to validate 
      
      good!xmllint成功的報出了錯誤!

      4. 關於--schema的輸出
      在講輸出之前先看下面一個場景,假如你想通過php執行xmllint然後拿到返回結果,你的代碼通常應該是這個樣子
      valid.php
      <?php  
      $command = "xmllint --noout --schema person.xsd person.xml";  
      exec($command, $output, $retval);  
      //出錯時返回值不為0  
      if ($retval != 0){   
              var_dump($output);      
      }  
      else{  
          echo "yeah!";  
      }
      
      我們保持上文中person.xml的錯誤。
      執行此代碼,你會發現,你拿到的output不是錯誤,而是array(0) {}, amazing!
      為什麼會這樣呢?
      因為xmllint --schema,如果驗證出錯誤,錯誤信息並不是通過標準輸出(stdout)顯示的,而是通過標準錯誤(stderr)進行顯示的。
      而exec的output參數拿到的,只能是標準輸出(stdout)顯示的內容。
      所以,為了拿到出錯信息,我們需要將標準錯誤重定向到標準輸出,對應修改代碼:
      $command = "xmllint --noout --schema person.xsd person.xml 2>&1";  

      再次執行valid.php,錯誤信息順利拿到!
      附小問題
      --noout參數關閉的是什麼輸出呢:)

      Monday, September 29, 2014

      打開Android C文件中的LOG

      資料來源: http://www.bobbog.com/archives/10

      可以一次打開LOGV,LOGI,LOGD,也可以分別打開:
      #undef NDEBUG       //打開LOGV/LOGI/LOGD
      #define LOG_NDEBUG   0  //打開LOGV
      #define LOG_NIDEBUG  0  //打開LOGI
      #define LOG_NDDEBUG 0 //打開LOGD
      

      舉例

      舉例,如果要看AndroidRuntime的LOGI和LOGD,可以有這樣2種寫法:

      方法一

      NDEBUG-LOG_NDEBUG=LOG_NIDEBUG +LOG_NIDEBUG
      #define LOG_TAG "AndroidRuntime"
      #undef NDEBUG
      #define LOG_NDEBUG 1
      #include <utils/Log.h>
      

      方法二

      LOG_NIDEBUG +LOG_NIDEBUG
      #define LOG_TAG "AndroidRuntime"
      #define LOG_NIDEBUG 0
      #define LOG_NDDEBUG 0
      #include <utils/Log.h>
      

      Wednesday, September 24, 2014

      git 打包的一个bash 函数


      資料來源: http://blog.csdn.net/free2o/article/details/3981786




      Here is my bash alias. The argument is the <branch name> to export.
      An example:
      
          cd /path/to/foo/
          _gittar master
      
      The output is (time in ISO 8601 / UTC):
      
          ../foot-YYYYMMDD.HHMM.tar.gz
      
      function _gittar ()
      {
          local name=$(pwd)
          name=${name##*/}
      
          if [ ! "$1" ]; then
              echo "[ERROR] what branch to export?"
              return 1
          fi
      
          local date=$(TZ=UTC date '+%Y%m%d.%H%M')
          local pkg="$name-$date"
          local dir=".."
          local tar="$dir/$pkg.tar.gz"
      
          git archive /
              --format=tar /
              --prefix="$pkg/" /
              "$@" |
          gzip --best > "$tar"
      
          echo $tar
      }