2014年1月22日 星期三

Construct 2教學:解析Platform 7 – parallax範例

本範例示範平台遊戲,加上背景圖層並設定圖層間視差效果
建立新專案
a.      New empty project
b.      Saveàplatform 7 – parallax.capx

決定場景及遊戲畫面尺寸
a.      Layout1Layout Size屬性:1280, 1024
b.      Project屬性:
Window Size
à640, 480
Fullscreen in browser
àoff
Nameàplatform 7 – parallax

在場景中加入跳板物件
a.      Insert new Objectà General/Sprite
Load an image from a fileà選取block.png
b.      Nameàboard
c.       Sizeà240, 35
d.      Behaviors
Add newàAttributes/Solid

Ctrl-drag複製5board
適當調整6board物件位置

加入玩家物件
a.      Insert new Objectà General/Sprite
Load an image from a fileà選取gear.png
b.      Nameàplayer
c.       Sizeà48, 48
d.      Behaviors
Add newàMovements/Platform

玩家掉落平台後自動重生
a.      切換到Event sheet
b.      Add event
playeràSize & Position/Is outside layout
c.       Add action
Playerà Size & Position/Set positionà130, 180

讓場景跟隨玩家捲動
a.      切換到Layout
b.      點選player
c.       Behaviors
Add newàGeneral/Scroll To

在場景上新增一個訊息圖層
a.      Layers面板/Add layer at top
b.      NameàUI layer
c.       TransparentàYes
d.      Parallaxà0, 0 (同步移動圖層,前後圖層沒有視差)
e.      點選Layer 0
f.        NameàPlayer layer

加入訊息物件
a.      Insert new Objectà General/Text
b.      Nameàscore
c.       LayeràUI layer
d.      Horizontal alignmentàLeft
e.      Vertical alignmentàTop
f.        Sizeà200, 22

取消預設使用方向鍵控制玩家物件
a.      點選player
b.      Behaviors/Platform/Default controlsàNo

加入鍵盤物件
a.      Insert new Objectà Input/Keyboard

設定按W鍵時使玩家跳躍
a.      切換到Event sheet
b.      Add event
KeyboardàKey is downàW
c.       Add action
playerà Platform/Simulation controlàJump

設定按D鍵時使玩家右移
a.      Add event
KeyboardàKey is downàD
b.      Add action
playerà Platform/Simulation controlàRight

設定按A鍵時使玩家右移
a.      Add event
KeyboardàKey is downàA
b.      Add action
playerà Platform/Simulation controlàLeft

設定專案為全螢幕執行
a.      專案屬性
Fullscreen in browseràCrop
b.      Layout1屬性
Unbounded scrollingàYes

切換到Layout
適當調整2board物件之大小、位置、角度,使其傾斜

在場景中加入移動跳板物件
a.      Insert new Objectà General/Sprite
b.      Load an image from a fileà選取block2.png
c.       Nameàmovingboard
d.      Sizeà150, 35
e.      LayeràLayer 0
f.        Behaviors
Add newàAttributes/Solid
g.      Behaviors
Add newàMovements/Sine
屬性:
Period
à5
Magnitude
à150

在場景上增加背景圖層
a.      Layers窗格/Add layer at top
b.      Move layer down調到最下層
c.       NameàBackground layer
d.      Background colorà204, 255, 255
e.      Parallaxà30, 30 (背景圖層與前面圖層移動視差30%)
f.        點選Player layer
TransparentàYes

加入背景雲物件
a.      Insert new Objectà General/Sprite
b.      Nameàcloud
c.       LayeràBackground layer

Ctrl-drag複製4cloud

適當調整5cloud物件位置