羅見順網站
返回
Action Script程式篇
01遊戲分鏡
FLA下載
執行檔下載
關鍵技術
遊戲開始、遊戲中、遊戲成就
按鈕製作
一般、滑入、按下、感應區
gotoAndStop(2);跳頁
02遊戲分鏡場景
FLA下載
關鍵技術
每一分鏡使用一場景
視窗/場景
新增場景-遊戲首頁、遊戲中、遊戲成就
gotoAndPlay(1,"遊戲中");跳至遊戲中場景的第1影格
03亂數
FLA下載
執行檔下載
參考程式
關鍵技術
產生0~1之間的亂數/乘以數字範圍/加上起始值
Math.floor: 去尾數
Math.random: 產生0~1之間的浮點亂數
04 四個可重複亂數
FLA下載
執行檔下載
參考程式
關鍵技術
呼叫亂數四次
genRnd(0, 9, 1);
05 四個不可重複亂數
FLA下載
執行檔下載
參考程式
關鍵技術
genRnd(0, 9, 4);
呼叫一次,取出四個
06 顯示滑鼠座標
FLA下載
執行檔下載
參考程式
關鍵技術
var mx:Number = mouseX;
var my:Number = mouseY;
this.mpos_txt.text= String(mx) + " , " + String(my);
07 自動生成
FLA下載
執行檔下載
參考程式
關鍵技術
元件生成
元件命名: bear_mc
宣告new產生物件: var actor_mc:bear_mc = new bear_mc();
加入舞台: addChild(actor_mc);
調整初始值:
actor_mc.x = 300;
actor_mc.y = 350;
actor_mc.scaleX = 1.3;
actor_mc.scaleY = 1.3;
影片片段加入滑鼠事件
滑入:MouseEvent.MOUSE_OVER
滑出:MouseEvent.MOUSE_OUT
滑鼠左鍵按下:MouseEvent.MOUSE_DOWN
滑鼠左鍵彈起:MouseEvent.MOUSE_UP
0701 砲彈陣列
FLA下載
執行檔下載
參考程式
關鍵技術
砲彈陣列生成
var BulletArray:Array=new Array(20);
BulletArray[i]=new bullet();
加入場景中:addChild(BulletArray[i]);
BulletArray[i].x= 30*i+30;
BulletArray[i].y=460;
設定深度:setChildIndex(BulletArray[i],1);
設定計時器0.5秒呼叫1次
var myTimer:Timer = new Timer(500);
myTimer.addEventListener(TimerEvent.TIMER, myTimerFunc);
myTimer.start();
將砲彈設定為主角中心位置射出
08 多重元件與鍵盤控制
FLA下載
執行檔下載
參考程式
關鍵技術
主角影片片段內含8個方向的走路動畫
鍵盤控制
取得鍵盤碼: var codeK:int = event.keyCode;
方向鍵:左(37)上(38)右(39)下(40)
Q(81):左上 W(87):上 E(69):右上
A(65):左 D(68):右
Z(90):左下 X(88):下 C(67):右下
多重選擇: switch(codeK)
09 拖曳
FLA下載
執行檔下載
參考程式
將主角綁在滑鼠游標上
actor_mc.startDrag(true, new Rectangle(50,50,540,300));
將主角解除滑鼠游標綁定
actor_mc.stopDrag();
09-1 點選物件移動
FLA下載
執行檔下載
參考程式
滑鼠左鍵按下事件:MouseEvent.MOUSE_DOWN
actor_mc.startDrag(true, new Rectangle(50,50,540,300));
滑鼠左鍵彈起事件:MouseEvent.MOUSE_UP
actor_mc.stopDrag();
09-2 物件追蹤滑鼠游標
FLA下載
執行檔下載
參考程式
建立ENTER_FRAME事件:addEventListener(Event.ENTER_FRAME, getMouseXY);
取得滑鼠座標:function getMouseXY(event:Event)
物件追蹤滑鼠:function moveTo(event:Event)
09-3 更換滑鼠游標
FLA下載
執行檔下載
參考程式
將滑鼠游標隱藏:Mouse.hide();
startDrag 更換的滑鼠圖片
將滑鼠游標顯示:Mouse.show();
stopDrag 更換的滑鼠圖片
10 HitTest
FLA下載
執行檔下載
參考程式
炮火進入戰機範圍框
actor_mc.hitTestObject(fire_mc)
炮火註冊點與戰機實際像素重疊
actor_mc.hitTestPoint(fire_mc.x, fire_mc.y, true)
炮火註冊點進入戰機範圍框
actor_mc.hitTestPoint(fire_mc.x, fire_mc.y, false)
11 倒數計時鈴響
FLA下載
執行檔下載
參考程式
建立Timer(以microseconds為單位):var myTimer:Timer = new Timer(100);
建立監聽:myTimer.addEventListener(TimerEvent.TIMER, myTimerFunc);
12 時鐘
FLA下載
執行檔下載
參考程式
建立 Date 物件:var today:Date = new Date();
取得時:var hr:int = today.getHours();
取得分:var min:int = today.getMinutes();
取得秒:var sec:int = today.getSeconds();