mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-15 03:21:35 +08:00
[phaser] Post pipeline support.
This commit is contained in:
parent
90cd61e505
commit
f725a80994
@ -350,6 +350,10 @@ cp -f ../spineboy/export/spineboy-pro.skel "$ROOT/spine-ts/spine-phaser/example/
|
||||
cp -f ../spineboy/export/spineboy-pma.atlas "$ROOT/spine-ts/spine-phaser/example/assets/"
|
||||
cp -f ../spineboy/export/spineboy-pma.png "$ROOT/spine-ts/spine-phaser/example/assets/"
|
||||
|
||||
cp -f ../coin/export/coin-pro.skel "$ROOT/spine-ts/spine-phaser/example/assets/"
|
||||
cp -f ../coin/export/coin-pma.atlas "$ROOT/spine-ts/spine-phaser/example/assets/"
|
||||
cp -f ../coin/export/coin-pma.png "$ROOT/spine-ts/spine-phaser/example/assets/"
|
||||
|
||||
echo "spine-monogame"
|
||||
rm "$ROOT/spine-monogame/spine-monogame-example/data/"*
|
||||
cp -f ../coin/export/coin-pro.json "$ROOT/spine-monogame/spine-monogame-example/data/"
|
||||
|
||||
59
spine-ts/spine-phaser/example/arcade-physics-test.html
Normal file
59
spine-ts/spine-phaser/example/arcade-physics-test.html
Normal file
@ -0,0 +1,59 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="//cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
|
||||
<script src="../dist/iife/spine-phaser.js"></script>
|
||||
<title>Spine Phaser Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Arcade Physics example</h1>
|
||||
</body>
|
||||
<script>
|
||||
var config = {
|
||||
type: Phaser.AUTO,
|
||||
width: 800,
|
||||
height: 600,
|
||||
type: Phaser.WEBGL,
|
||||
physics: {
|
||||
default: 'arcade',
|
||||
arcade: {
|
||||
debug: true,
|
||||
gravity: { y: 200 }
|
||||
}
|
||||
},
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
},
|
||||
plugins: {
|
||||
scene: [
|
||||
{ key: "spine.SpinePlugin", plugin: spine.SpinePlugin, mapping: "spine" }
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
let game = new Phaser.Game(config);
|
||||
|
||||
function preload () {
|
||||
this.load.spineBinary("coin-data", "assets/coin-pro.skel");
|
||||
this.load.spineAtlas("coin-atlas", "assets/coin-pma.atlas");
|
||||
}
|
||||
|
||||
function create () {
|
||||
let coin = this.add.spine(400, 200, 'coin-data', "coin-atlas");
|
||||
coin.animationState.setAnimation(0, "animation", true);
|
||||
coin.setScale(0.3);
|
||||
coin.setSize(280, 280);
|
||||
|
||||
this.physics.add.existing(coin);
|
||||
|
||||
coin.body.setOffset(0, 50);
|
||||
coin.body.setVelocity(100, 200);
|
||||
coin.body.setBounce(1, 1);
|
||||
coin.body.setCollideWorldBounds(true);
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
19
spine-ts/spine-phaser/example/assets/coin-pma.atlas
Normal file
19
spine-ts/spine-phaser/example/assets/coin-pma.atlas
Normal file
@ -0,0 +1,19 @@
|
||||
coin-pma.png
|
||||
size: 1024, 1024
|
||||
filter: Linear, Linear
|
||||
pma: true
|
||||
coin-front-logo
|
||||
bounds: 2, 570, 305, 302
|
||||
coin-front-shine-logo
|
||||
bounds: 2, 286, 282, 282
|
||||
coin-front-shine-spineboy
|
||||
bounds: 305, 283, 282, 282
|
||||
coin-front-spineboy
|
||||
bounds: 309, 567, 305, 302
|
||||
rotate: 90
|
||||
coin-side-round
|
||||
bounds: 2, 2, 144, 282
|
||||
coin-side-straight
|
||||
bounds: 286, 286, 17, 282
|
||||
shine
|
||||
bounds: 148, 39, 72, 245
|
||||
BIN
spine-ts/spine-phaser/example/assets/coin-pma.png
Normal file
BIN
spine-ts/spine-phaser/example/assets/coin-pma.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 222 KiB |
BIN
spine-ts/spine-phaser/example/assets/coin-pro.skel
Normal file
BIN
spine-ts/spine-phaser/example/assets/coin-pro.skel
Normal file
Binary file not shown.
70
spine-ts/spine-phaser/example/blend-test.html
Normal file
70
spine-ts/spine-phaser/example/blend-test.html
Normal file
@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="//cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
|
||||
<script src="../dist/iife/spine-phaser.js"></script>
|
||||
<title>Spine Phaser Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Blend test</h1>
|
||||
</body>
|
||||
<script>
|
||||
var config = {
|
||||
type: Phaser.AUTO,
|
||||
width: 800,
|
||||
height: 600,
|
||||
type: Phaser.WEBGL,
|
||||
backgroundColor: '#cdcdcd',
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
update: update
|
||||
},
|
||||
plugins: {
|
||||
scene: [
|
||||
{ key: "spine.SpinePlugin", plugin: spine.SpinePlugin, mapping: "spine" }
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
let controls;
|
||||
let game = new Phaser.Game(config);
|
||||
|
||||
function preload () {
|
||||
this.load.spineBinary("spineboy-data", "assets/spineboy-pro.skel");
|
||||
this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas");
|
||||
}
|
||||
|
||||
function create () {
|
||||
for (var i = 0; i < 4; i++) {
|
||||
let obj = this.add.spine(i * 200, 600, 'spineboy-data', 'spineboy-atlas').setScale(0.25);
|
||||
obj.setScale(0.25);
|
||||
obj.animationState.setAnimation(0, "idle", true);
|
||||
obj.animationState.setAnimation(1, "shoot", true);
|
||||
}
|
||||
var cursors = this.input.keyboard.createCursorKeys();
|
||||
|
||||
var controlConfig = {
|
||||
camera: this.cameras.main,
|
||||
left: cursors.left,
|
||||
right: cursors.right,
|
||||
up: cursors.up,
|
||||
down: cursors.down,
|
||||
zoomIn: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q),
|
||||
zoomOut: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E),
|
||||
acceleration: 0.35,
|
||||
drag: 0.01,
|
||||
maxSpeed: 1.2
|
||||
};
|
||||
|
||||
controls = new Phaser.Cameras.Controls.SmoothedKeyControl(controlConfig);
|
||||
}
|
||||
|
||||
function update (time, delta) {
|
||||
controls.update(delta);
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
113
spine-ts/spine-phaser/example/camera-pipeline-test.html
Normal file
113
spine-ts/spine-phaser/example/camera-pipeline-test.html
Normal file
@ -0,0 +1,113 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="//cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
|
||||
<script src="../dist/iife/spine-phaser.js"></script>
|
||||
<title>Spine Phaser Example</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Camera pipeline test</h1>
|
||||
<script>
|
||||
var config = {
|
||||
type: Phaser.AUTO,
|
||||
width: 800,
|
||||
height: 600,
|
||||
type: Phaser.WEBGL,
|
||||
backgroundColor: '#cdcdcd',
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
},
|
||||
plugins: {
|
||||
scene: [
|
||||
{ key: "spine.SpinePlugin", plugin: spine.SpinePlugin, mapping: "spine" }
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const fragShader = `
|
||||
#define SHADER_NAME PLASMA_FS
|
||||
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D uMainSampler;
|
||||
uniform float uTime;
|
||||
uniform vec2 uResolution;
|
||||
|
||||
varying vec2 outTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / uResolution.xy;
|
||||
|
||||
float x = p.x;
|
||||
float y = p.y;
|
||||
float mov0 = x+y+cos(sin(uTime)*2.0)*100.+sin(x/100.)*1000.;
|
||||
float mov1 = y / 0.9 + uTime;
|
||||
float mov2 = x / 0.2;
|
||||
float c1 = abs(sin(mov1+uTime)/2.+mov2/2.-mov1-mov2+uTime);
|
||||
float c2 = abs(sin(c1+sin(mov0/1000.+uTime)+sin(y/40.+uTime)+sin((x+y)/100.)*3.));
|
||||
float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
|
||||
|
||||
vec4 pixel = texture2D(uMainSampler, outTexCoord);
|
||||
|
||||
gl_FragColor = pixel * vec4(c1, c2, c3, 1);
|
||||
}
|
||||
`;
|
||||
|
||||
class PlasmaPostFX extends Phaser.Renderer.WebGL.Pipelines.PostFXPipeline {
|
||||
constructor(game) {
|
||||
super({
|
||||
game,
|
||||
name: 'PlasmaPostFX',
|
||||
fragShader,
|
||||
uniforms: [
|
||||
'uMainSampler',
|
||||
'uTime',
|
||||
'uResolution'
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
onPreRender() {
|
||||
this.set1f('uTime', this.game.loop.time / 1000);
|
||||
}
|
||||
|
||||
onDraw(renderTarget) {
|
||||
this.set2f('uResolution', renderTarget.width, renderTarget.height);
|
||||
|
||||
this.bindAndDraw(renderTarget);
|
||||
}
|
||||
}
|
||||
|
||||
let game = new Phaser.Game(config);
|
||||
|
||||
function preload() {
|
||||
this.load.spineBinary("spineboy-data", "assets/spineboy-pro.skel");
|
||||
this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas");
|
||||
this.load.image("img", "assets/raptor-pma.png")
|
||||
}
|
||||
|
||||
function create() {
|
||||
this.renderer.pipelines.addPostPipeline('PlasmaPostFX', PlasmaPostFX);
|
||||
|
||||
// FIXME: Need a dummy sprite so the MultiPipeline sets up state
|
||||
// so rendering the Spine sprite actually works. Unsure what state
|
||||
// is needed.
|
||||
var s = this.add.sprite(0, 0, 'img');
|
||||
|
||||
let spineboy = this.add.spine(400, 300, 'spineboy-data', "spineboy-atlas");
|
||||
spineboy.scale = 0.5;
|
||||
spineboy.animationState.setAnimation(0, "walk", true);
|
||||
|
||||
this.cameras.main.setPostPipeline("PlasmaPostFX");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -15,6 +15,9 @@
|
||||
<li><a href="./multi-scene-test.html">Multi-scene test</a></li>
|
||||
<li><a href="./bounds-test.html">Bounds test</a></li>
|
||||
<li><a href="./visibility-test.html">Visibility test</a></li>
|
||||
<li><a href="./arcade-physics-test.html">Arcade physics example</a></li>
|
||||
<li><a href="./blend-test.html">Blend test</a></li>
|
||||
<li><a href="./camera-pipeline-test.html">Camera pipeline test</a></li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
@ -39,8 +39,8 @@ export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsPro
|
||||
const animationState = new AnimationState(gameObject.animationState.data);
|
||||
const skeleton = new Skeleton(gameObject.skeleton.data);
|
||||
const data = skeleton.data;
|
||||
let customSkin = new Skin("custom-skin");
|
||||
if (this.skins.length > 0) {
|
||||
let customSkin = new Skin("custom-skin");
|
||||
for (const skinName of this.skins) {
|
||||
const skin = data.findSkin(skinName);
|
||||
if (skin == null) continue;
|
||||
@ -51,15 +51,11 @@ export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsPro
|
||||
skeleton.setToSetupPose();
|
||||
|
||||
const animation = this.animation != null ? data.findAnimation(this.animation!) : null;
|
||||
let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
|
||||
if (animation == null) {
|
||||
skeleton.updateWorldTransform();
|
||||
const bounds = skeleton.getBoundsRect();
|
||||
minX = bounds.x;
|
||||
minY = bounds.y;
|
||||
maxX = minX + bounds.width;
|
||||
maxY = minY + bounds.height;
|
||||
return skeleton.getBoundsRect();
|
||||
} else {
|
||||
let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
|
||||
animationState.clearTracks();
|
||||
animationState.setAnimationWith(0, animation, false);
|
||||
const steps = Math.max(animation.duration / this.timeStep, 1.0);
|
||||
@ -74,8 +70,8 @@ export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsPro
|
||||
maxX = Math.max(maxX, minX + bounds.width);
|
||||
maxY = Math.max(maxY, minY + bounds.height);
|
||||
}
|
||||
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
||||
}
|
||||
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user