-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29bf176
commit 127faaf
Showing
18 changed files
with
445 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set main=./examples/effect-properties/displacement.js | ||
cd .. | ||
cd .. | ||
npm run watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import phaser from 'phaser/src/phaser.js'; | ||
import EffectPropertiesPlugin from '../../plugins/effectproperties-plugin.js'; | ||
|
||
class Demo extends Phaser.Scene { | ||
constructor() { | ||
super({ | ||
key: 'examples' | ||
}) | ||
} | ||
|
||
preload() { | ||
this.load.image('logo', 'assets/images/logo.png'); | ||
|
||
//this.load.image('distort', 'assets/images/distortion/noisesmall.png'); | ||
this.load.image('distort', 'assets/images/distortion/distortion.png'); | ||
} | ||
|
||
create() { | ||
var image = this.add.image(400, 300, 'logo'); | ||
this.plugins.get('rexEffectProperties').add(image); | ||
|
||
image.displacementKey = 'distort'; | ||
image.displacementX = -0.03; | ||
image.displacementY = -0.03; | ||
|
||
} | ||
|
||
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: 'rexEffectProperties', | ||
plugin: EffectPropertiesPlugin, | ||
start: true | ||
}] | ||
} | ||
}; | ||
|
||
var game = new Phaser.Game(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set main=./examples/effect-properties/gradient.js | ||
cd .. | ||
cd .. | ||
npm run watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import phaser from 'phaser/src/phaser.js'; | ||
import EffectPropertiesPlugin from '../../plugins/effectproperties-plugin.js'; | ||
|
||
class Demo extends Phaser.Scene { | ||
constructor() { | ||
super({ | ||
key: 'examples' | ||
}) | ||
} | ||
|
||
preload() { | ||
this.load.image('logo', 'assets/images/logo.png'); | ||
} | ||
|
||
create() { | ||
var image = this.add.image(400, 300, 'logo'); | ||
this.plugins.get('rexEffectProperties').add(image); | ||
|
||
image.gradientColor = [0x0000ff, 0x00ff00]; | ||
|
||
} | ||
|
||
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: 'rexEffectProperties', | ||
plugin: EffectPropertiesPlugin, | ||
start: true | ||
}] | ||
} | ||
}; | ||
|
||
var game = new Phaser.Game(config); |
14 changes: 14 additions & 0 deletions
14
plugins/behaviors/effectproperties/AddDisplacementProperties.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default AddDisplacementProperties; | ||
|
||
declare namespace AddDisplacementProperties { | ||
interface DisplacementGameObject extends Phaser.GameObjects.GameObject { | ||
displacementKey: string | null | false; | ||
displacementX: number; | ||
displacementY: number; | ||
|
||
} | ||
} | ||
|
||
declare function AddDisplacementProperties( | ||
gameObject: Phaser.GameObjects.GameObject | ||
): AddDisplacementProperties.DisplacementGameObject; |
84 changes: 84 additions & 0 deletions
84
plugins/behaviors/effectproperties/AddDisplacementProperties.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import HasProperty from '../../utils/object/HasProperty.js'; | ||
import GetFXFactory from './GetFXFactory.js'; | ||
|
||
var AddDisplacementProperties = function (gameObject) { | ||
// Don't attach properties again | ||
if (HasProperty(gameObject, 'displacementKey')) { | ||
return gameObject; | ||
} | ||
|
||
var fxFactory = GetFXFactory(gameObject); | ||
if (!fxFactory) { | ||
return gameObject; | ||
} | ||
|
||
var displacementKey, | ||
displacementX = 0.005, | ||
displacementY = 0.005; | ||
Object.defineProperty(gameObject, 'displacementKey', { | ||
get: function () { | ||
return displacementKey; | ||
}, | ||
set: function (value) { | ||
if (displacementKey === value) { | ||
return; | ||
} | ||
|
||
displacementKey = value; | ||
|
||
if ((displacementKey === null) || (displacementKey === false)) { | ||
if (gameObject._displacement) { | ||
fxFactory.remove(gameObject._displacement); | ||
gameObject._displacement = undefined; | ||
} | ||
} else { | ||
if (!gameObject._displacement) { | ||
gameObject._displacement = fxFactory.addDisplacement(displacementKey, displacementX, displacementY); | ||
} | ||
|
||
gameObject._displacement.setTexture(displacementKey); | ||
} | ||
|
||
}, | ||
}) | ||
|
||
Object.defineProperty(gameObject, 'displacementX', { | ||
get: function () { | ||
return displacementX; | ||
}, | ||
set: function (value) { | ||
if (displacementX === value) { | ||
return; | ||
} | ||
|
||
displacementX = value; | ||
|
||
if (gameObject._displacement) { | ||
gameObject._displacement.x = displacementX; | ||
} | ||
}, | ||
}) | ||
|
||
Object.defineProperty(gameObject, 'displacementY', { | ||
get: function () { | ||
return displacementY; | ||
}, | ||
set: function (value) { | ||
if (displacementY === value) { | ||
return; | ||
} | ||
|
||
displacementY = value; | ||
|
||
if (gameObject._displacement) { | ||
gameObject._displacement.y = displacementY; | ||
} | ||
}, | ||
}) | ||
|
||
gameObject.displacementKey = null; | ||
|
||
return gameObject; | ||
} | ||
|
||
export default AddDisplacementProperties; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
plugins/behaviors/effectproperties/AddGradientProperties.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default AddGradientProperties; | ||
|
||
declare namespace AddGradientProperties { | ||
interface GradientGameObject extends Phaser.GameObjects.GameObject { | ||
gradientColor: [number, number] | null | false; | ||
gradientColor1: number | null | false; | ||
gradientColor2: number | null | false; | ||
gradientAlpha: number; | ||
gradientFromX: number; | ||
gradientFromY: number; | ||
gradientToX: number; | ||
gradientToY: number; | ||
gradientSize: number; | ||
|
||
} | ||
} | ||
|
||
declare function AddGradientProperties( | ||
gameObject: Phaser.GameObjects.GameObject | ||
): AddGradientProperties.GradientGameObject; |
Oops, something went wrong.