-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phaser 3 restart the scene armature not animate #140
Comments
Too. i think it's a phaser 3 problem. After scene chenging armature don't loading any more... |
Hey, guys! Sorry I just saw this. I had this problem ages ago, but digging in the source code was able to solve it. Before switching scenes or restarting, you need to destroy the armature and clear the dragonbones pool. I typically put the scene change inside of a setTimeout, just to be sure. So example: `this.player.armature.destroy(); setTimeout(()=>{ @jentleyonadoss @Stasikiii I hope this helps! If you have questions, let me know and maybe I can answer! |
@faradaym Hi. Ths for answer this. But i have no property armature of my player. this.load.dragonbone("player","characters/player/player_tex.png","characters/player/player_tex.json","characters/player/player_ske.json"); player.armature.destroy is not a function and whe i can find this.dragonbone.factory.clear(true); SceneMain.dragonbone.factory.clear(true); Pls help. :( |
@Stasikiii in your case,
|
@photonstorm Hello, Richard. Glad to answered my question, but i still stuck on this last Month :( I moved those lines of code you did pointed for me, but still no effect :( after scenes chenging my dragonbones character every time disapeart. My scene:
No errors, game runned normaly. |
That code really doesn't look right to me. Some obvious things:
I would use a much more standard approach to your Scenes, like the following (assuming ES6, but easy to backport to ES5 if you need): export class SceneMain extends Phaser.Scene
{
constructor ()
{
super('SceneMain');
}
preload ()
{
this.load.dragonbone("doc",
"characters/doc/doc_tex.png",
"characters/doc/doc_tex.json",
"characters/doc/doc_ske.json"
);
}
create ()
{
this.player = this.add.armature('doc', 'doc_test');
this.events.once('shutdown', this.shutdown, this);
// Do stuff, when finished, move to another Scene, this will trigger the shutdown event
}
shutdown ()
{
this.player.destroy();
this.dragonbone.factory.clear(true);
dragonBones.BaseObject.clearPool(true);
}
}
const config = {
width: 800,
height: 600,
backgroundColor: 0x0,
plugins: {
scene: [
{ key: "DragonBones", plugin: dragonBones.phaser.plugin.DragonBonesScenePlugin, mapping: "dragonbone" }
]
},
scene: [ SceneMain ]
};
new Phaser.Game(config); Obviously, you cannot just run this code directly. But you should clearly see the approach. The scope of your calls is of paramount importance in JavaScript. |
@photonstorm thx for answer. I don't sure about ES6, i can't try on this moment becuse of error about export. One more. I adding some code in dragonBones.js in line 16042 after "textureAtlasData = dragonBones_3.BaseObject.borrowObject(phaser.display.TextureAtlasData);" Now I don't even know what to do with all of this. :( <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="api/phaser.js"></script>
<script src="api/dragonBones.js"></script>
</head>
<script>
class SceneMain extends Phaser.Scene {
constructor ()
{
super('SceneMain');
}
preload ()
{
this.load.dragonbone("doc",
"characters/doc/doc_tex.png",
"characters/doc/doc_tex.json",
"characters/doc/doc_ske.json"
);
}
create ()
{
this.player = this.add.armature('doc_test', 'doc');
this.player.setPosition(300, 500);
this.player.animation.play("idle");
this.input.on('pointerup', function (pointer) {
this.scene.start('SceneMain2');
}, this);
this.events.once('shutdown', this.shutdown, this);
}
shutdown ()
{
console.log("*****************");
this.player.destroy();
this.dragonbone.factory.clear(true);
dragonBones.BaseObject.clearPool(true);
}
}
class SceneMain2 extends Phaser.Scene {
constructor ()
{
super('SceneMain2');
}
preload ()
{
this.load.dragonbone("doc",
"characters/doc/doc_tex.png",
"characters/doc/doc_tex.json",
"characters/doc/doc_ske.json"
);
}
create ()
{
this.player = this.add.armature('doc_test', 'doc');
this.player.setPosition(500, 500);
this.player.animation.play("idle");
this.input.on('pointerup', function (pointer) {
this.scene.start('SceneMain');
}, this);
this.events.once('shutdown', this.shutdown, this);
}
shutdown ()
{
console.log("!!!!!!!!!!!!!!!");
this.player.destroy();
this.dragonbone.factory.clear(true);
dragonBones.BaseObject.clearPool(true);
}
}
const config = {
type: Phaser.WEBGL,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
width: 1920,
height: 1080
},
audio: {
noAudio: true
},
plugins: {
scene: [
{ key: "DragonBones", plugin: dragonBones.phaser.plugin.DragonBonesScenePlugin, mapping: "dragonbone" }
]
},
scene: [ SceneMain,SceneMain2 ]
};
var game = new Phaser.Game(config);
</script> With no succes :( |
when I star scene newly all animation are working very good but once I restart the scene all armature are not animating
The text was updated successfully, but these errors were encountered: