Animations now load dynamically and are cached
This commit is contained in:
@ -24,7 +24,6 @@ export async function loadTexture(scene: Phaser.Scene, assetData: AssetDataT): P
|
||||
// If asset is found, add it to the scene
|
||||
if (asset) {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
console.log(asset.data)
|
||||
scene.textures.addBase64(asset.key, asset.data)
|
||||
scene.textures.once(`addtexture-${asset.key}`, () => {
|
||||
gameStore.game.loadedAssets.push(asset)
|
||||
@ -39,6 +38,7 @@ export async function loadTexture(scene: Phaser.Scene, assetData: AssetDataT): P
|
||||
export async function loadSpriteTextures(scene: Phaser.Scene, sprite: Sprite) {
|
||||
const sprite_actions = await fetch(config.server_endpoint + '/assets/list_sprite_actions/' + sprite?.id).then((response) => response.json())
|
||||
for await (const sprite_action of sprite_actions) {
|
||||
|
||||
await loadTexture(scene, {
|
||||
key: sprite_action.key,
|
||||
data: sprite_action.data,
|
||||
@ -49,14 +49,18 @@ export async function loadSpriteTextures(scene: Phaser.Scene, sprite: Sprite) {
|
||||
frameHeight: sprite_action.frameHeight
|
||||
} as AssetDataT)
|
||||
|
||||
if (sprite_action.isAnimated) {
|
||||
scene.anims.create({
|
||||
key: sprite_action.key,
|
||||
frameRate: 7,
|
||||
frames: scene.anims.generateFrameNumbers(sprite_action.key, { start: 0, end: sprite_action.frameCount! - 1 }),
|
||||
repeat: -1
|
||||
})
|
||||
}
|
||||
// If the sprite is not animated, skip
|
||||
if (!sprite_action.isAnimated) continue
|
||||
|
||||
// Add the animation to the scene
|
||||
const anim = scene.textures.get(sprite_action.key)
|
||||
scene.textures.addSpriteSheet(sprite_action.key, anim, { frameWidth: sprite_action.frameWidth ?? 0, frameHeight: sprite_action.frameHeight ?? 0 })
|
||||
scene.anims.create({
|
||||
key: sprite_action.key,
|
||||
frameRate: 7,
|
||||
frames: scene.anims.generateFrameNumbers(sprite_action.key, { start: 0, end: sprite_action.frameCount! - 1 }),
|
||||
repeat: -1
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user