JyunWei-Su
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    ###### tags: `blogger` date: `2018.02` :::danger 本文章為舊版Blogger內容轉移,目前暫停維護 ::: # App Inventor 使用畫布及球型精靈製作遊戲搖桿(蘑菇頭) <p style="text-align:center;"><img src="https://1.bp.blogspot.com/-2DoyNZ3-twY/YP52nlpOe7I/AAAAAAAAWUw/6HWtXPgF8ewLzyT7qTlCe4QFTLtwLZ-GACLcBGAsYHQ/s0/EoPhR5i.png" width="100"></p> ## 一.摘要 &emsp;&emsp;使用App Inventor製作遊戲,其中一個不可或缺的元件就是搖桿了,很多人想做卻不知如何下手,接下來這篇文章就帶著你來完成一個遊戲搖桿。 ## 二.運作架構 1. 使用`畫布`元件作為搖桿移動的範圍 2. 此用`球型精靈`作為搖桿 3. 程式初始化時將球型精靈至於畫布中央 4. 在畫布上畫一個半透明的圓(作為視覺上的邊界) 5. 當搖桿(球型精靈)被按下時讀取位置並做適當偏移(保持搖桿中心位於所繪之半透明圓內) <p style="text-align:center;"><img src="https://i.imgur.com/HI5WLYL.gif" width="60%"></p> 6. 以上是文言文,接下來舉例說明: * 範例專案中(載點在文章末),畫布的大小為`150*150`像素,搖桿的半徑為`25`像素 * ==注意:畫布的圓點在畫布的左上角,並非習慣上的直角座標系,而搖桿的定位點也並非位於圓心,而是位於圓外左上角的兩圓切弦交點。== <p style="text-align:center;"><img src="https://i.imgur.com/y4Ic5hp.png" width="30%">&nbsp;<img src="https://i.imgur.com/2yPP4GZ.png" width="30%"></p> 以下圖為例: <p style="text-align:center;"><img src="https://i.imgur.com/yR7ZyOK.png" width="60%"></p> * 畫布的長寬皆為`150`像素(==注意==:畫布必須為正方形)。 * 而畫布的中心點座標就會是`(75,75)`,並在中心座標畫上一個半徑為`50`的圓`(75-25)`。當今天搖桿(球型精靈)被拖曳: * (1) 先假設畫布偵測到你的手位於畫布座標`(25,75)`,很明顯你的手的位置距離中心點剛好是50,因為在繪製的圓以內 所以不用做任何調整,則必須將搖桿移動到座標`(0,50)`的位置,這樣圓心就會位於`(25,75)`了。 * (2)再假設你的手位於座標`(125,25)`,我們可以利用`距離公式`算出,手的位置距離中心點70.71$(=50 * \sqrt 2)$,這時就使用==比例縮放==的方式可以算出搖桿的中心應該要被調整到(110.66,39.34),$110.66 = 75+((125-75)*\frac{50}{70.1})$,$39.34 = 75+((25-75)*\frac{50}{70.1})$,而搖桿就必須移動到`(85.66,14.34)`了 * (3)依此類推即可。上面所舉例的數字在計算時皆取到小數點後第2位,所以必定會有誤差請勿在意因舉例所發生的誤差。 ## 三.畫面編排 * 需要一個水平布局內置一個畫布 * 畫布內有一個球型精靈 * 畫布旁須置一個標籤來顯示搖桿的xy位置 * 音效可有可無,用來給予使用者震動回饋 * 建議將工作面板下的第二個勾選框打勾會較容易排板 <p style="text-align:center;"><img src="https://i.imgur.com/GO1aLW1.png" width="85%"></p> ## 四.程式設計 1. 變數宣告 * (1)`搖桿x`儲存的是`手指的x座標-畫布中心`,意即搖桿中心的x座標 * (2)`搖桿y`同理搖桿x * (3)`畫布中心`即為(畫布邊長/2) * (4)`搖桿離心距離`為手的座標距離畫布中心之距離 * (5)`搖桿基準暨半徑`為背景圓的半徑,也等於搖桿中心位於畫布中心時,搖桿的座標 <p style="text-align:center;"><img src="https://i.imgur.com/O93XT0j.png" width="70%"></p> 2. 初始化 * (1)將`搖桿基準暨半徑`設為(半個畫布寬-搖桿半徑)=(75-25) * (2)`畫布中心`即為半個畫布寬 * (3)將搖桿移到畫布中心 * (4)畫背景圓,其中顏色的四碼分別為`(R,G,B,透明度)` * (5)設定`標籤`的基本參數 <p style="text-align:center;"><img src="https://i.imgur.com/dByl6vo.png" width="85%"></p> 3. 當搖桿被拖曳(移動位置),詳細運作方式如==2.運作架構==所說明 <p style="text-align:center;"><img src="https://i.imgur.com/uMx3gjW.png" width="85%"></p> 4. 其他 * (1)當搖桿被點擊時,給予使用者回饋 * (2)當搖桿被鬆開時,將搖桿移回畫布中心 * (3)當手機的"返回上一頁"按鈕被按下時關閉程式 <p style="text-align:center;"><img src="https://i.imgur.com/W8gquf0.png" width="85%"></p> ## 五.自定義設定 &emsp;&emsp;您可以在App inventor 2 畫面編排的模式下自訂以下參數: 1. 搖桿與畫布的大小,畫布必須是正方形。建議您畫布的長寬要是搖桿半徑的5倍以上(本專案是6倍)。 2. 當搖桿被點擊時的震動長度 3. 上述未提及的版面配置等... ## 六.心得與範例檔載點 [搖桿(蘑菇頭).aia](https://drive.google.com/open?id=13f_s_kyUarMqjnvKvr-iPpc-dWE89_Xr) [搖桿(蘑菇頭).apk](https://drive.google.com/open?id=1hqcosJqVj15ioNamQTnsdmD5StHr709a) &emsp;&emsp;希望這篇文章能對你有所幫助,相信各位有了搖桿不僅是在遊戲的控制上更加靈活,更能增添遊戲角色移動的流暢度。 &emsp;&emsp;不過 目前App inventor 似乎尚未支援多點觸控部分功能(例如同時控制兩個搖桿)還是無法執行待日後AI2 官方推出更新必定能發展出無限的可能。日後將有一篇文章來介紹App inventor的擴充功能。 ==再次感謝您的閱讀 ❤❤❤==

    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