Knowhow-dm2
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Egret Manual ## Visual Studio Code ### 開啟專案 開啟資料夾 ![](https://i.imgur.com/w2VguLl.png) 選擇專案目標 ![](https://i.imgur.com/0zHbKXc.png) --- ### 運行專案 開啟 <font color = #FF0000>**Terminal**</font> ![](https://i.imgur.com/I28yJj8.png) 運行專案 <font color = #FF0000>**egret run**</font> -a -a 為 auto-compile 自動編譯,可不輸入 ![](https://i.imgur.com/hfiUacC.png) --- ## 引擎架構與流程 ### Stage 每個項目必須存在且唯一的容器,你可以把 stage 想像成是 scene 的容器 ### Lifecycle * onPause:當網頁進入 unfocus 狀態時觸發 * onResume:當網頁恢復 focus 狀態時觸發 * [官方文件](http://developer.egret.com/en/2d/getStarted/lifecycle) ### 專案結構 ![](https://i.imgur.com/oIkYT7X.png) | | 內容 | | -------- | -------- | | .wing | 放置專案設定 (如:Screen 寬高、版本)、任務配置、啟動配置 | | bin-debug | 編譯調試後的 js 檔案,內容應與 src 底下的檔案一致 (ts to js) | | libs | 各種 module、底層與第三方 library | | **resource** | 各種美術資源 (如:圖檔、Skin) | | scripts | 發佈平台用的底層腳本群 | | <font color = #FF0000>**src**</font> | 專案程式碼 (放置我們實作功能的地方) | | template | 放置模板 (如:index.html、native loader) | | **egretProperties.json** | 放置專案設定 (如:引擎版本、resource 來源) | | favicon.ico | 即網頁 icon 圖示 | | **index.html** | 即網頁入口 (來自 template 的 index.html) | | manifest.json | 紀錄網頁清單 (你可以想像成 js list) | | tsconfig.json | 設定編譯方式與編譯來源 | | wingProperties.json | Expose 給 Egret Wing 的設定 (理論上不影響編譯) | --- ## Skin Part 白話文:UI 元件,如 Button, Label, Rect 這些都是 Skin 就是透過這些 UI 元件組成的,所以被命名為 Skin Part 當 Logic (ts) 綁定 Skin (exml)時,引擎底層會自動 bind 相同 ID 的 UI 元件 示例: ![](https://i.imgur.com/NyWPb3E.png) ![](https://i.imgur.com/F0FFWDG.png) 只要綁定的 Skin (exml) 有設定 UI 的 ID 就會觸發 partAdded,這個方法主要是讓你可以對 UI 做一些初始化設定,而不是在 Skin 端寫死 ``` protected partAdded(partName: string, instance: any): void ``` --- ## Visual Studio 2019 ### 安裝必要套件 開啟 **Visual Studio Installer**, 選擇安裝 **Node.js 開發** ![](https://i.imgur.com/qKENIpi.png) 開啟專案方法和VS Code相同 ### 運行專案 * 開啟 **View/Terminal** (預設是PowerShell, 可到Setting更換) * 開啟 **Tools/Command Line/** * **Developer Command Prompt** * **Developer PowerShell** * 開啟 **Tools/NuGet Package Manager/Package Manager Console** ### Issue * NuGet Package Manager Console的中文會變成亂碼 * NuGet Package Manager Console執行egret run後就無法停止 --- ## Egret UI Editor ### 開啟專案 開啟資料夾 ![](https://i.imgur.com/boNLGm6.png) 選擇專案目標 ![](https://i.imgur.com/0zHbKXc.png) --- ### Skin UI 元件 (*exml*) --- #### 新增 Skin ![](https://i.imgur.com/lpoQMbs.png) 此時你的畫面應該要長這樣,mySkin 為剛剛創立的 Skin ![](https://i.imgur.com/iahEdcX.png) 拖入一個 Rect 元件 (此步驟非必要,單純方便演示) ![](https://i.imgur.com/GHINrqV.png) 將 Rect 佈滿畫面 (此步驟非必要,單純方便演示) ![](https://i.imgur.com/7nGDH2Z.png) 放入一個 Label (此步驟非必要,單純方便演示) ![](https://i.imgur.com/QrXaKJT.png) --- #### 匯入 Skin 回到 VS Code 並創建一個 TestMySkin.ts 第一種宣告 skin 來源的方式: 在 constructor 宣告位置 (即上述步驟所創建的 mySkin 位置) ![](https://i.imgur.com/9MEHkht.png) 第二種宣告 skin 來源的方式: 在 resource/default.thm.json 裡新增位置 (即上述步驟所創建的 mySkin 位置) 類別對應 Skin ![](https://i.imgur.com/YU5I4hW.png) 在 Main.ts (專案核心) 呼叫創建 TestMySkin ![](https://i.imgur.com/gLl5UIG.png) 重新編譯後就能看到剛剛的創建的 Skin 囉 ![](https://i.imgur.com/HcPyAMC.png) --- #### 定義自己的 Skin 位置 在 resource 底下新增資料夾 ![](https://i.imgur.com/Eb50h7q.png) 在 egretProperties.json 新增 eui 來源位置 ![](https://i.imgur.com/gbUdigA.png) 回到 Egret UI Editor 沒有看見,請先試著 Reload 如果還是無法顯示, 請檢查 egretProperties.json 是否有語法錯誤 ![](https://i.imgur.com/e283uQ8.png) **<font color=#ff0000>skin更名, exml 的 class name 會被加料, 需要自行檢查</font>** --- ### Anchor設定 * 假設有個 50x20 的矩形, 想設定中心點在正中間 * unity: **x=0.5 y=0.5** * egret: **x=25 y=10** --- ## Tween Sequence 基本用法 ``` let tween = egret.Tween.get(指定物件, { loop: true }); tween.to({ alpha: 1}, 200); tween.wait(500); tween.to({ alpha: 0.5}, 200); tween.wait(500); tween.play(); ``` 同時播放多個效果 ``` let tween = egret.Tween.get(指定物件, { loop: true }); tween.to({ alpha: 1, scaleX: 1.5, scaleY: 1.5 }, 200); tween.wait(500); tween.to({ alpha: 0.5, scaleX: 1, scaleY: 1 }, 200); tween.wait(500); tween.play(); ``` --- ## Atlas 可以使用 **Texture Merger** 來產生 Atlas 的圖片檔 ![](https://i.imgur.com/Xs1qdSw.png) 打開之後選擇 **Sprite Sheet** ![](https://i.imgur.com/qWi2RiO.png) 將選擇的圖片拖到右側 ![](https://i.imgur.com/EYW8cEm.png) 這樣就產生熟悉的畫面了 ![](https://i.imgur.com/SBHyqLG.png) 左下角可以變更圖片排列的設定 ![](https://i.imgur.com/c7DwYxi.png) 接著使用 Export 匯出 Atlas 和 json 檔案 ![](https://i.imgur.com/zQZZIIC.png) ![](https://i.imgur.com/EpxfiSa.png) 將這兩個檔案放到 egret 的 resource\assets 下面,並且將兩個檔案拖到 資源編輯器(default.res.json)裡面 ![](https://i.imgur.com/SSRUxia.png) 這樣就能看到 Atlas 被匯入到資源編輯器裡面了 ![](https://i.imgur.com/uLEJ954.png) Subkeys 代表這個 Atlas 下所有圖片的名稱,最後就可以在 UI Editor 的 asset 裡面看到 Atlas 所有的圖片了 ![](https://i.imgur.com/aQRmabZ.png) --- ### 使用 particle * [導入particle library](https://hackmd.io/laBGtO7NRVGkXu8kIbZoIA#%E4%BB%A5%E5%AE%98%E6%96%B9%E6%8E%A8%E8%96%A6%E7%9A%84%E7%89%A9%E7%90%86%E5%BC%95%E6%93%8Ep2%E7%82%BA%E4%BE%8B) * 使用工具 **Egret Feather** 輸出 snow 範本, 會有2個檔案 ``` 檔名.json 檔名.png ``` * 將檔案匯入到resource - [參考DragonBones匯入方法](https://hackmd.io/P7dkrekcS-GFM8IaZqWjKg#%E5%8C%AF%E5%85%A5%E8%B3%87%E6%BA%90%E5%88%B0-Egret-%E5%B0%88%E6%A1%88) * 使用方法 ``` let config = RES.getRes("檔名_json"); let tex: egret.Texture = RES.getRes("檔名_png"); let sys = new particle.GravityParticleSystem(tex, config); sys.explosionParticle.start(); this.addChild(sys); ``` --- ### 發佈正式版本 * 打開 console 輸入 **egret publish** * 專案底下會出現資料夾 **bin-release** * 需要放到 http server 才能觀看 * 只要修改專案中 **\*.min** 的檔案,修改後的內容也會被發佈出來 --- ### eui.ItemRenderer 的 data * data 預設型別是 any :::warning class 繼承 eui.ItemRenderer 可複寫 data, 並指定型別 ::: :::danger data 不能指定預設值, 否則會經由 eui.js 定義的 setter 觸發 dataChanged(), 造成流程上的問題 ::: :::spoiler ``` get: function () { return this._data; }, set: function (value) { this._data = value; eui.PropertyEvent.dispatchPropertyEvent(this, eui.PropertyEvent.PROPERTY_CHANGE, "data"); this.dataChanged(); }, ``` ::: --- ### 5.3.5 之前的版本使用 TTF :::success ```css= <style type="text/css"> @font-face { font-family: 'myFont'; src:url('font/myFont.TTF') format('truetype'); font-weight: normal; font-style: normal; } .egret-player{ font-family: "myFont"; } </style> ``` label 的 fontFamily 需要手動指定成 css 上面設定的字型名稱 ::: --- ## 相關文章 [官方手冊](http://developer.egret.com/cn/github/egret-docs/Engine2D/index.html?home=2) [無痛起手 Egret](https://ithelp.ithome.com.tw/articles/10211534) [Egret FAQ](/b1E2Ft89Q9K25m9xVh31OA) ###### tags: `教學`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully