/
Demo.hx
77 lines (65 loc) · 2.55 KB
/
Demo.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ;
import com.pblabs.components.scene2D.CircleShape;
import com.pblabs.components.scene2D.SceneAlignment;
import com.pblabs.components.spatial.SpatialComponent;
import com.pblabs.components.tasks.FunctionTask;
import com.pblabs.components.tasks.LocationTask;
import com.pblabs.components.tasks.RepeatingTask;
import com.pblabs.components.tasks.SerialTask;
import com.pblabs.engine.core.PBContext;
import com.pblabs.engine.core.PBGame;
import com.pblabs.engine.core.SignalBondManager;
using Lambda;
using com.pblabs.components.scene2D.SceneUtil;
using com.pblabs.components.tasks.TaskUtil;
using com.pblabs.engine.core.PBGameUtil;
using com.pblabs.engine.util.PBUtil;
class Demo
{
public function new()
{
//Setup logging.
com.pblabs.engine.debug.Log.setup();
var game = new PBGame();
game.addBaseManagers();
//The main "context". This is equivalent to a level, or a menu screen.
var context :PBContext = game.pushContext(PBContext);
//This method is via 'using' SceneUtil
var scene2D = context.createBaseScene();
scene2D.sceneAlignment = SceneAlignment.TOP_LEFT;
var layer = scene2D.addLayer("defaultLayer");
//Create our blob that we will move around.
var so = context.createBaseSceneEntity();
// var blob = context.allocate(com.pblabs.components.scene2D.RectangleShape);
// blob.borderRadius = 10;
var blob = context.allocate(com.pblabs.components.scene2D.CircleShape);
// blob.radius = 30;
blob.fillColor = 0xff0000;
blob.width = 100;
// blob.height = 300;
blob.parentProperty = layer.entityProp();
so.addComponent(blob);
so.initialize("SomeSceneObj");
var topLeft = scene2D.getAlignedPoint(SceneAlignment.TOP_LEFT);
var topRight = scene2D.getAlignedPoint(SceneAlignment.TOP_RIGHT);
var bottomRight = scene2D.getAlignedPoint(SceneAlignment.BOTTOM_RIGHT);
var bottomLeft = scene2D.getAlignedPoint(SceneAlignment.BOTTOM_LEFT);
//This method is via 'using' SceneUtil
so.setLocation(50, 100);
//This method is via 'using' TaskUtil
so.addTask(new RepeatingTask(
new SerialTask(
LocationTask.CreateEaseOut(topLeft.x + blob.width / 2, topLeft.y + blob.height / 2, 2),
LocationTask.CreateEaseOut(topRight.x - blob.width / 2, topRight.y + blob.height / 2, 2),
LocationTask.CreateEaseOut(bottomRight.x - blob.width / 2, bottomRight.y - blob.height / 2, 2),
LocationTask.CreateEaseOut(bottomLeft.x + blob.width / 2, bottomLeft.y - blob.height / 2, 2)
)
));
//Prevents the first frame have the location at (0,0)
scene2D.update();
}
public static function main()
{
new Demo();
}
}