construct 2進階操作
DESCRIPTION
介紹Construct 2設定事件、子事件、全域變數、物件變數、家族變數、AddonsTRANSCRIPT
Dept. of Electronics Engineering
Construct 2進階操作電子工程系電腦遊戲設計組
吳錫修
2014.3.14
Wu, ShyiShiou2
聲音檔
在Construct 2中,音效和音樂都是使用音頻文件,任何專案中使用到的聲音文件,都要隨專案⼀起匯出
由於瀏覽器廠商尚未達成⼀致的Web聲音檔標準,聲音檔必須同時編碼為兩種格式:Ogg Vorbis格式 (.ogg) 和MPEG-4 AAC (.m4a)
Wu, ShyiShiou3
Projects/Sounds快顯功能表 Import sounds
匯入音效檔
Wu, ShyiShiou4
匯入音樂檔
Projects/Music快顯功能表 Import music
Wu, ShyiShiou5
Wu, ShyiShiou6
獨立事件
Construct 2每個tick由上到下依序執行事件表
事件組成
單擊Margin處,可以選取整個event
Wu, ShyiShiou7
建立多條件事件 1/2
多重事件同時發生
1. Add event
2. Margin快顯功能表Add another condition
Wu, ShyiShiou8
建立多條件事件 2/2
多重事件之⼀發生
1. Add event
2. Margin快顯功能表Add another condition
3. Margin快顯功能表Make 'Or' block
Wu, ShyiShiou9
建立子事件
行為類似多重事件同時發生,但父事件與子事件可以有各自的action
父事件的action執行後才會執行子事件
Wu, ShyiShiou10
使用事件群組 1/3
將相關作業事件群組起來以方便管理
1. 在事件表中新增群組 (Add group)
Wu, ShyiShiou11
使用事件群組 2/3
2. 在群組中加入子事件 (Add sub-event)
Wu, ShyiShiou12
使用事件群組 3/3
群組作業
Toogle disabled啟用/禁用群組事件
Toggle bookmark標示/移除書籤
Toggle breakpoint設置/清除中斷點
Replace object更換群組中的物件
Expand all groups展開所有群組
Collapse all groups摺疊所有群組
Wu, ShyiShiou13
Wu, ShyiShiou14
Function物件
使用Function物件可讓我們在事件表中定義函式及呼叫定義函式
加入Function物件
Wu, ShyiShiou15
定義Function
1. Add event Function
2. 選擇Function/On function
3. 指定函式名稱
Wu, ShyiShiou16
使用function參數
Function Add another condition
Wu, ShyiShiou17
Function回傳值
1. 在事件表的action中,使用Function/Set return value
2. 設定回傳值
Wu, ShyiShiou18
呼叫Function
在事件表的action中,使用Function/Call function指定function名稱及參數 (視需要)
Wu, ShyiShiou19
使用Function expressions
呼叫函式
Function.Call ("函式名稱", 參數1, 參數2…)
參數值
Function.Param(i) 取得參數,i表示以0起始的參數索引值
參數個數
Function.ParamCount
傳回值
Function.ReturnValue
Wu, ShyiShiou20
Function應用實例
計算N!
0! = 1
N! = N * (N-1)!
Wu, ShyiShiou21
Wu, ShyiShiou22
全域變數 global variable
整份事件表共用
支援Number及Text資料型別
Wu, ShyiShiou23
區域變數 local variable
定義在群組或子事件中
Wu, ShyiShiou24
物件個體變數
每⼀個物件個體各別擁有
支援Boolean、Number及Text資料型別
Wu, ShyiShiou25
家族成員變數 1/2
建立家族
設定家族成員
Wu, ShyiShiou26
家族成員變數 2/2
在家族增加成員變數
每⼀個家族成員都具備的變數
支援Boolean、Number及Text資料型別
Wu, ShyiShiou27
Wu, ShyiShiou28
Addons是什麼?
第三方開發人員可使用JavaScript SDK擴展Construct 2的behavior外掛程式或effect外掛程式,統稱為addons
behavior及plugin由4個檔案組成
common.js
edittime.js
PluginIcon.ico
runtime.js
新版addons還有⼀個info.xml檔
effect由2個檔案組成
effect_name.fx
effect_name.xml
Wu, ShyiShiou29
線上資源
C2 Plugins and Behaviors List
http://www.scirra.com/forum/c2-plugins-and-behaviors-list_topic47002.html
SDK template
http://www.scirra.com/downloads/javascript-sdk-template.zip
Wu, ShyiShiou30
安裝外掛程式 1/2
新版外掛程式
副檔名.c2addon
將c2addon文件拖曳到Construct 2
會安裝到Application data\construct 2目錄之behaviors、effects、plugins子目錄下,每個plugin及behavior會再各別建立子目錄
Wu, ShyiShiou31
安裝外掛程式 2/2
舊版外掛程式
Zip壓縮檔
安裝路徑
<install path>\exporters\html5\plugins for plugins<install path>\exporters\html5\behaviors for behaviors<install path>\effects for effects
每個plugin及behavior要各別建立子目錄,將外掛程式解壓到子目錄下
Wu, ShyiShiou32
info.xml
<?xml version="1.0" encoding="UTF-8" ?><c2addon>
<!-- One of: plugin, behavior, effect --><type>behavior</type>
<name>My Super Behavior</name><version>1.0</version><author>Ashley Gullen</author><website>http://www.scirra.com</website><documentation>https://www.scirra.com/manual/1/construct-2</documentation><description>A short description of what this addon does.</description>
</c2addon>
Wu, ShyiShiou33
common.js
// Scripts in this file are included in both the IDE and runtime, so you only// need to write scripts common to both once.
Wu, ShyiShiou34
function GetBehaviorSettings() {return {
"name": "MyBehavior", // as appears in 'add behavior' dialog, can be changed as long as "id" stays the same
"id": "MyBehavior", // this is used to identify this behavior and is saved to the project; never change it
“version”: “1.0”, // Behavior版本 - C2據此顯示相容性警告"description": "<appears at the bottom of the add behavior dialog>","author": "<your name/organisation>","help url": "<your website or a manual entry on Scirra.com>","category": "General", // Prefer to re-use existing
categories, but you can set anything here"flags": 0 // uncomment lines to enable flags...
// | bf_onlyone // can only be added once to an object, e.g. solid
};};
//////////////////////////////////////// Wu, ShyiShiou35