From 1bca2ad66376718d4657e87b7555d855ea03b95e Mon Sep 17 00:00:00 2001 From: Rex Date: Sat, 25 Nov 2023 12:10:55 +0800 Subject: [PATCH] Add test code --- examples/test/dropdown-shadow.bat | 4 + .../test/{postfx.js => dropdown-shadow.js} | 6 +- examples/test/outline.bat | 4 + examples/test/outline.js | 82 +++++++++++++++++++ examples/test/postfx.bat | 4 - examples/test/shadow.bat | 4 + examples/test/shadow.js | 63 ++++++++++++++ 7 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 examples/test/dropdown-shadow.bat rename examples/test/{postfx.js => dropdown-shadow.js} (90%) create mode 100644 examples/test/outline.bat create mode 100644 examples/test/outline.js delete mode 100644 examples/test/postfx.bat create mode 100644 examples/test/shadow.bat create mode 100644 examples/test/shadow.js diff --git a/examples/test/dropdown-shadow.bat b/examples/test/dropdown-shadow.bat new file mode 100644 index 0000000000..83d5fa14da --- /dev/null +++ b/examples/test/dropdown-shadow.bat @@ -0,0 +1,4 @@ +set main=./examples/test/dropdown-shadow.js +cd .. +cd .. +npm run watch \ No newline at end of file diff --git a/examples/test/postfx.js b/examples/test/dropdown-shadow.js similarity index 90% rename from examples/test/postfx.js rename to examples/test/dropdown-shadow.js index 010497537d..81c5ceb54d 100644 --- a/examples/test/postfx.js +++ b/examples/test/dropdown-shadow.js @@ -20,7 +20,8 @@ class Demo extends Phaser.Scene { this.add.image(400, 300, 'classroom') - var gameObject = this.add.image(400, 300, 'mushroom') + // var gameObject = this.add.image(400, 300, 'mushroom') + var gameObject = this.add.line(400, 300, -50, 0, 50, 0, 0x00ff00).setLineWidth(10) gameObject.moveTo = this.plugins.get('rexMoveTo').add(gameObject, { speed: 400, rotateToTarget: true @@ -47,6 +48,9 @@ class Demo extends Phaser.Scene { var touchY = pointer.y; gameObject.moveTo.moveTo(touchX, touchY); }); + + + this.cameras.main.startFollow(gameObject); } update() { diff --git a/examples/test/outline.bat b/examples/test/outline.bat new file mode 100644 index 0000000000..2d227e3dda --- /dev/null +++ b/examples/test/outline.bat @@ -0,0 +1,4 @@ +set main=./examples/test/outline.js +cd .. +cd .. +npm run watch \ No newline at end of file diff --git a/examples/test/outline.js b/examples/test/outline.js new file mode 100644 index 0000000000..a777545967 --- /dev/null +++ b/examples/test/outline.js @@ -0,0 +1,82 @@ +import phaser from 'phaser/src/phaser.js'; +import OutlinePipelinePlugin from '../../plugins/outlinepipeline-plugin.js'; +import MoveToPlugin from '../../plugins/moveto-plugin.js'; + + +class Demo extends Phaser.Scene { + constructor() { + super({ + key: 'examples' + }) + } + + preload() { + this.load.image('mushroom', 'assets/images/mushroom.png'); + this.load.image('classroom', 'assets/images/backgrounds/classroom.png'); + } + + create() { + var postFxPlugin = this.plugins.get('rexOutlinePipeline'); + + this.add.image(400, 300, 'classroom') + + var gameObject = this.add.image(400, 300, 'mushroom') + gameObject.moveTo = this.plugins.get('rexMoveTo').add(gameObject, { + speed: 400, + rotateToTarget: true + }) + .on('start', function (dot, moveTo) { + if (postFxPlugin.get(gameObject)[0]) { + return; + } + + postFxPlugin.add(gameObject, { + thickness: 5, + outlineColor: 0xff0000 + }); + }) + .on('complete', function () { + postFxPlugin.remove(gameObject); + }) + + this.input.on('pointerdown', function (pointer) { + var touchX = pointer.x; + var touchY = pointer.y; + gameObject.moveTo.moveTo(touchX, touchY); + }); + + + this.cameras.main.startFollow(gameObject); + } + + update() { + } +} + +var config = { + type: Phaser.AUTO, + parent: 'phaser-example', + width: 800, + height: 600, + scale: { + mode: Phaser.Scale.FIT, + autoCenter: Phaser.Scale.CENTER_BOTH, + }, + scene: Demo, + plugins: { + global: [ + { + key: 'rexOutlinePipeline', + plugin: OutlinePipelinePlugin, + start: true + }, + { + key: 'rexMoveTo', + plugin: MoveToPlugin, + start: true + } + ] + } +}; + +var game = new Phaser.Game(config); \ No newline at end of file diff --git a/examples/test/postfx.bat b/examples/test/postfx.bat deleted file mode 100644 index 4d776bdf50..0000000000 --- a/examples/test/postfx.bat +++ /dev/null @@ -1,4 +0,0 @@ -set main=./examples/test/postfx.js -cd .. -cd .. -npm run watch \ No newline at end of file diff --git a/examples/test/shadow.bat b/examples/test/shadow.bat new file mode 100644 index 0000000000..e18dd76ad6 --- /dev/null +++ b/examples/test/shadow.bat @@ -0,0 +1,4 @@ +set main=./examples/test/shadow.js +cd .. +cd .. +npm run watch \ No newline at end of file diff --git a/examples/test/shadow.js b/examples/test/shadow.js new file mode 100644 index 0000000000..74fc0706dd --- /dev/null +++ b/examples/test/shadow.js @@ -0,0 +1,63 @@ +import phaser from 'phaser/src/phaser.js'; +import MoveToPlugin from '../../plugins/moveto-plugin.js'; + + +class Demo extends Phaser.Scene { + constructor() { + super({ + key: 'examples' + }) + } + + preload() { + this.load.image('mushroom', 'assets/images/mushroom.png'); + this.load.image('classroom', 'assets/images/backgrounds/classroom.png'); + } + + create() { + this.add.image(400, 300, 'classroom') + + var gameObject = this.add.image(400, 300, 'mushroom') + gameObject.postFX.addShadow(10, -10, 0.006, 1, 0xff0000, 10); + + gameObject.moveTo = this.plugins.get('rexMoveTo').add(gameObject, { + tspeed: 400, + rotateToTarget: true + }) + + this.input.on('pointerdown', function (pointer) { + var touchX = pointer.x; + var touchY = pointer.y; + gameObject.moveTo.moveTo(touchX, touchY); + }); + + + this.cameras.main.startFollow(gameObject); + } + + update() { + } +} + +var config = { + type: Phaser.AUTO, + parent: 'phaser-example', + width: 800, + height: 600, + scale: { + mode: Phaser.Scale.FIT, + autoCenter: Phaser.Scale.CENTER_BOTH, + }, + scene: Demo, + plugins: { + global: [ + { + key: 'rexMoveTo', + plugin: MoveToPlugin, + start: true + } + ] + } +}; + +var game = new Phaser.Game(config); \ No newline at end of file