mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
[phaser] Expose getters for preloaded skeleton data and atlases.
This commit is contained in:
parent
f8837604f5
commit
5662c75db9
@ -14,15 +14,30 @@
|
||||
<h1>Basic example</h1>
|
||||
</body>
|
||||
<script>
|
||||
class BasicScene extends Phaser.Scene {
|
||||
preload() {
|
||||
this.load.spineBinary("spineboy-data", "assets/spineboy-pro.skel");
|
||||
this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas");
|
||||
}
|
||||
|
||||
create() {
|
||||
const spineboy = this.add.spine(400, 500, 'spineboy-data', "spineboy-atlas");
|
||||
spineboy.scale = 0.5;
|
||||
spineboy.animationState.setAnimation(0, "walk", true);
|
||||
|
||||
const spineboy2 = this.make.spine({
|
||||
x: 200, y: 500, dataKey: "spineboy-data", atlasKey: "spineboy-atlas"
|
||||
});
|
||||
this.add.existing(spineboy2);
|
||||
}
|
||||
}
|
||||
|
||||
const config = {
|
||||
type: Phaser.AUTO,
|
||||
width: 800,
|
||||
height: 600,
|
||||
type: Phaser.WEBGL,
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
},
|
||||
scene: [BasicScene],
|
||||
plugins: {
|
||||
scene: [
|
||||
{ key: "spine.SpinePlugin", plugin: spine.SpinePlugin, mapping: "spine" }
|
||||
@ -31,22 +46,6 @@
|
||||
};
|
||||
|
||||
const 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() {
|
||||
const spineboy = this.add.spine(400, 500, 'spineboy-data', "spineboy-atlas");
|
||||
spineboy.scale = 0.5;
|
||||
spineboy.animationState.setAnimation(0, "walk", true);
|
||||
|
||||
const spineboy2 = this.make.spine({
|
||||
x: 200, y: 500, dataKey: "spineboy-data", atlasKey: "spineboy-atlas"
|
||||
});
|
||||
this.add(spineboy2);
|
||||
}
|
||||
</script>
|
||||
|
||||
</html>
|
||||
@ -112,7 +112,7 @@ export class SpinePlugin extends Phaser.Plugins.ScenePlugin {
|
||||
return gameObject;
|
||||
};
|
||||
|
||||
let makeSpineGameObject = function (this: Phaser.GameObjects.GameObjectFactory, config: SpineGameObjectConfig, addToScene: boolean) {
|
||||
let makeSpineGameObject = function (this: Phaser.GameObjects.GameObjectFactory, config: SpineGameObjectConfig, addToScene: boolean = false) {
|
||||
let x = config.x ? config.x : 0;
|
||||
let y = config.y ? config.y : 0;
|
||||
let boundsProvider = config.boundsProvider ? config.boundsProvider : undefined;
|
||||
@ -184,10 +184,10 @@ export class SpinePlugin extends Phaser.Plugins.ScenePlugin {
|
||||
}
|
||||
|
||||
createSkeleton (dataKey: string, atlasKey: string) {
|
||||
return new Skeleton(this.createSkeletonData(dataKey, atlasKey));
|
||||
return new Skeleton(this.getSkeletonData(dataKey, atlasKey));
|
||||
}
|
||||
|
||||
createAtlas(atlasKey: string) {
|
||||
getAtlas(atlasKey: string) {
|
||||
let atlas: TextureAtlas;
|
||||
if (this.atlasCache.exists(atlasKey)) {
|
||||
atlas = this.atlasCache.get(atlasKey);
|
||||
@ -210,8 +210,8 @@ export class SpinePlugin extends Phaser.Plugins.ScenePlugin {
|
||||
return atlas;
|
||||
}
|
||||
|
||||
createSkeletonData(dataKey: string, atlasKey: string) {
|
||||
const atlas = this.createAtlas(atlasKey)
|
||||
getSkeletonData(dataKey: string, atlasKey: string) {
|
||||
const atlas = this.getAtlas(atlasKey)
|
||||
const combinedKey = dataKey + atlasKey;
|
||||
let skeletonData: SkeletonData;
|
||||
if (this.skeletonDataCache.exists(combinedKey)) {
|
||||
|
||||
@ -28,4 +28,10 @@ declare global {
|
||||
spine (config: SpineGameObjectConfig, addToScene?: boolean): SpineGameObject;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Phaser {
|
||||
export interface Scene {
|
||||
spine: SpinePlugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user