|
@@ -1,16 +1,50 @@
|
|
|
-let test, but, bu2;
|
|
|
+let test, but;
|
|
|
|
|
|
class TestObject extends Object2D
|
|
|
{
|
|
|
_setup()
|
|
|
{
|
|
|
- this.position.y = 300;
|
|
|
- this.position.x = 100;
|
|
|
+ this.visible = true;
|
|
|
+ this.position = new Vector2(100, 100);
|
|
|
+ this.getChildByIndex(0).connect("buttonPressed", this, "_onSignal");
|
|
|
+ }
|
|
|
+
|
|
|
+ _onSignal(param1, param2, param3, param4)
|
|
|
+ {
|
|
|
+ this.visible = !this.visible;
|
|
|
+ console.log(param1);
|
|
|
+ console.log(param2);
|
|
|
+ console.log(param3);
|
|
|
+ console.log(param4);
|
|
|
+ }
|
|
|
+
|
|
|
+ _update(delta)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ _draw(delta)
|
|
|
+ {
|
|
|
+ if (this.visible) ellipse(0, 0, 20);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- this.tween = new Tween("myTween");
|
|
|
- this.tween.interpolateProperty(this.position, "x", PROPERTY_TYPE.NUMBER, this.position.x, 400, 2, TRANS_TYPE.LINEAR);
|
|
|
- this.tween.interpolateProperty(this.position, "y", PROPERTY_TYPE.NUMBER, this.position.y, 100, 2, TRANS_TYPE.BOUNCE, EASE_TYPE.OUT);
|
|
|
- this.addChild(this.tween);
|
|
|
+class TestObject2 extends Object2D
|
|
|
+{
|
|
|
+ _setup()
|
|
|
+ {
|
|
|
+ this.visible = true;
|
|
|
+ this.position = new Vector2(200, 100);
|
|
|
+ but.connect("buttonPressed", this, "_onSignal");
|
|
|
+ }
|
|
|
+
|
|
|
+ _onSignal(param1, param2, param3, param4)
|
|
|
+ {
|
|
|
+ this.visible = !this.visible;
|
|
|
+ console.log(param1);
|
|
|
+ console.log(param2);
|
|
|
+ console.log(param3);
|
|
|
+ console.log(param4);
|
|
|
}
|
|
|
|
|
|
_update(delta)
|
|
@@ -20,23 +54,26 @@ class TestObject extends Object2D
|
|
|
|
|
|
_draw(delta)
|
|
|
{
|
|
|
- ellipse(0, 0, 20);
|
|
|
+ if (this.visible) ellipse(0, 0, 20);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class TestButton extends Button
|
|
|
{
|
|
|
- _onMousePressed()
|
|
|
+ _initSignals()
|
|
|
{
|
|
|
- if (this.name == "b1")
|
|
|
- this.getParent().tween.start();
|
|
|
- else if (this.name == "b2")
|
|
|
- this.getParent().tween.stop();
|
|
|
- else if (this.name == "b3")
|
|
|
- this.getParent().tween.stopByIndex(0);
|
|
|
- else if (this.name == "b4")
|
|
|
- this.getParent().tween.startByIndex(0);
|
|
|
+ this.addSignal("buttonPressed");
|
|
|
+ }
|
|
|
|
|
|
+ _setup()
|
|
|
+ {
|
|
|
+ this.setPosition(200, 200);
|
|
|
+ this.setSize(100, 50)
|
|
|
+ }
|
|
|
+
|
|
|
+ _onMousePressed()
|
|
|
+ {
|
|
|
+ this.emitSignal("buttonPressed", 1, 2, 3, 4);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -56,19 +93,10 @@ function setup()
|
|
|
textFont(AssetHandler.getP5FontByName("Lato"));
|
|
|
|
|
|
test = new TestObject("myTest");
|
|
|
- but = new TestButton("b1", "play");
|
|
|
- but.setPosition(0, 200);
|
|
|
+ but = new TestButton("b1", "Emit signal");
|
|
|
test.addChild(but);
|
|
|
- but2 = new TestButton("b2", "stop");
|
|
|
- but2.setPosition(0, 230);
|
|
|
- test.addChild(but2);
|
|
|
- but2 = new TestButton("b3", "stop1");
|
|
|
- but2.setPosition(0, 260);
|
|
|
- test.addChild(but2);
|
|
|
- but2 = new TestButton("b4", "play1");
|
|
|
- but2.setPosition(0, 290);
|
|
|
- test.addChild(but2);
|
|
|
GameHandler.addRootObject(test);
|
|
|
+ GameHandler.addRootObject(new TestObject2("myTest2"))
|
|
|
}
|
|
|
|
|
|
function draw()
|