root/as3/BetweenAS3/trunk/tests/fp10/PhysicalTest.as

リビジョン 3019, 3.3 kB (コミッタ: yossy, コミット時期: 4 年 前)

BetweenAS3: Merged "Dramatic Before After" branch to trunk.

Line 
1 /*
2  * BetweenAS3
3  *
4  * Licensed under the MIT License
5  *
6  * Copyright (c) 2009 BeInteractive! (www.be-interactive.org) and
7  *                    Spark project  (www.libspark.org)
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  *
27  */
28 package
29 {
30         import flash.display.Shape;
31         import flash.display.Sprite;
32         import flash.events.Event;
33         import flash.events.MouseEvent;
34         import org.libspark.betweenas3.BetweenAS3;
35         import org.libspark.betweenas3.easing.*;
36         import org.libspark.betweenas3.tweens.ITween;
37        
38         /**
39          * @author      yossy:beinteractive
40          */
41         [SWF(width = 800, height = 600, frameRate = 30, backgroundColor = 0xffffff)]
42         public class PhysicalTest extends Sprite
43         {
44                 public function PhysicalTest()
45                 {
46                         setupBackground();
47                        
48                         var box1:Box = addChild(new Box()) as Box;
49                         var box2:Box = addChild(new Box()) as Box;
50                         // var box3:Box = addChild(new Box()) as Box;
51                         var box4:Box = addChild(new Box()) as Box;
52                        
53                         _t = BetweenAS3.parallel(
54                                 BetweenAS3.physical(box1, {x: 700, y: 120}, {x: 100, y: 120}, Physical.uniform(24.0)),
55                                 BetweenAS3.physical(box2, {x: 700, y: 240}, {x: 100, y: 240}, Physical.accelerate(2.0, 4.0)),
56                                 // BetweenAS3.tween(box3, {x: 700, y: 360}, {x: 100, y: 360}, 1.0, Back.easeInOut),
57                                 BetweenAS3.physical(box4, {x: 700, y: 480}, {x: 100, y: 480}, Physical.exponential(0.2, 0.0001))
58                         );
59                        
60                         _t.play();
61                        
62                         stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler)
63                 }
64                
65                 private var _t:ITween;
66                
67                 private function setupBackground():void
68                 {
69                         var bg:Shape = new Shape();
70                         bg.graphics.beginFill(0xffffff);
71                         bg.graphics.drawRect(0, 0, 800, 600);
72                         bg.graphics.endFill();
73                         bg.graphics.beginFill(0xcccccc);
74                         bg.graphics.drawRect(100, 0, 1, 600);
75                         bg.graphics.drawRect(700, 0, 1, 600);
76                         bg.graphics.endFill();
77                         addChild(bg);
78                 }
79                
80                 private function mouseDownHandler(e:MouseEvent):void
81                 {
82                         if (_t.isPlaying) {
83                                 _t.stop();
84                         }
85                         else {
86                                 if (_t.position == _t.duration) {
87                                         _t.gotoAndPlay(0);
88                                 }
89                                 else {
90                                         _t.play();
91                                 }
92                         }
93                 }
94         }
95 }
96
97 import flash.display.Shape;
98
99 internal class Box extends Shape
100 {
101         public function Box()
102         {
103                 graphics.beginFill(0x000000);
104                 graphics.drawRect(-10, -10, 20, 20);
105                 graphics.endFill();
106         }
107 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。