Using image swap in Phaser
Re: Using image swap in Phaser
Alright, then that's what I'm gonna do
Re: Using image swap in Phaser
I'm experiencing some strange behaviour in Phaser when using image swap:
Starting up the game, everything works fine and as expected. When I switch to another game state and then start the state the creature is in again, all meshes that have Sprite Swap activated (not necessarily in use) don't show up and even setting a new swap tag number won't bring them back. I can't find anything wrong on my side, it works fine with animations that don't use sprite swap.
edit: I'm using the flatdata files (.bytes) if it's of any help
Starting up the game, everything works fine and as expected. When I switch to another game state and then start the state the creature is in again, all meshes that have Sprite Swap activated (not necessarily in use) don't show up and even setting a new swap tag number won't bring them back. I can't find anything wrong on my side, it works fine with animations that don't use sprite swap.
edit: I'm using the flatdata files (.bytes) if it's of any help
Re: Using image swap in Phaser
Hello,
I am not sure if this is relevant but when you load up the character again in the new state ( or any state for that matter ), you should load a copy of the original JSON/Flatbuffers byte stream.
You should try constructing ( if you aren't already ) a new character with a new byte stream. The core Creature libraries should work and shouldn't care about other characters, if you check the code that is the case ( the ones on Github ).
If you are referring to going back to the current state and the sprite swap meshes are not visible, that is very strange. I do not think the code in the creature object is aware of the state. A work around is to save out the current frame and active animation name of your character, then when you go back to the state you remove the old character and instantiate a new one with the saved data. ( I am suspecting Phaser itself might be modifying internal Creature object data, Creature itself does not as far as I know ) The official Creature runtimes on the GitHub page are different from the Phaser CE version. Most of the Creature state data is stored in the CreatureManager and Creature objects which shouldn't contain or be aware of any Phaser specific states.
Thanks
I am not sure if this is relevant but when you load up the character again in the new state ( or any state for that matter ), you should load a copy of the original JSON/Flatbuffers byte stream.
You should try constructing ( if you aren't already ) a new character with a new byte stream. The core Creature libraries should work and shouldn't care about other characters, if you check the code that is the case ( the ones on Github ).
If you are referring to going back to the current state and the sprite swap meshes are not visible, that is very strange. I do not think the code in the creature object is aware of the state. A work around is to save out the current frame and active animation name of your character, then when you go back to the state you remove the old character and instantiate a new one with the saved data. ( I am suspecting Phaser itself might be modifying internal Creature object data, Creature itself does not as far as I know ) The official Creature runtimes on the GitHub page are different from the Phaser CE version. Most of the Creature state data is stored in the CreatureManager and Creature objects which shouldn't contain or be aware of any Phaser specific states.
Thanks
Re: Using image swap in Phaser
The state is set to be created freshly and I'm not using the CE versions of creature but the core files. What I do in the creation of my state is basically this:
Code: Select all
var actual_data = null;
actual_data = CreatureModuleUtils.LoadCreatureFlatData(new Uint8Array(game.cache.getBinary(jsonkey)));
var new_creature = new Creature(actual_data, true);
var new_manager = new CreatureManager(new_creature);
var creaturePhasorObject = new Phaser.CreatureDraw(game.world,
x,
y,
new_manager,
texture);
return(creaturePhasorObject);
I am, right?chong wrote:You should try constructing ( if you aren't already ) a new character with a new byte stream.
Re: Using image swap in Phaser
Hello,
Yes that looks right, however short of actual debugging I am afraid I can't decipher too much info about what is actually going on. For this sort of problem, ideally it will be great if a small sample test case can be used to repro the bug. Otherwise it will be difficult to know what is going on.
Update: Did you also create and load the required animations? The animations need to be added to the manager.
Thanks
Yes that looks right, however short of actual debugging I am afraid I can't decipher too much info about what is actually going on. For this sort of problem, ideally it will be great if a small sample test case can be used to repro the bug. Otherwise it will be difficult to know what is going on.
Update: Did you also create and load the required animations? The animations need to be added to the manager.
Thanks
Re: Using image swap in Phaser
Yes, I do create and load the animations, just didn't copy the text now...
I could build a reduced version of my code to make it easier to investigate and send that to you.
I could build a reduced version of my code to make it easier to investigate and send that to you.
Re: Using image swap in Phaser
Hello,
I think I solved it, at least from my local test:
Creature needs a new cloned array.The one passed in from Phaser after loading might be modified once by the FlatBuffers library. So it needs a fresh, clean copy. I cloned the source FlatBuffers array and it could switch + swap properly.
Thanks
I think I solved it, at least from my local test:
Code: Select all
// Make a pure clone/copy of the Uint8Array buffer
function copyArray(src) {
var dst = src.slice(0);
return dst;
}
//{ CREATURE
function addCreature (game, texturekey, jsonkey, x, y, width = "auto", height ="auto", animationkeys = ["default"], loop=false, play=true, flatdata=false, activeanimation = "start", check = false) {
var texture = new PIXI.Texture(game.cache.getBaseTexture(texturekey));
var actual_data = null;
if(flatdata) {
// Clone array
var curArray = copyArray(new Uint8Array(game.cache.getBinary(jsonkey)));
// Load in array data
actual_data = CreatureModuleUtils.LoadCreatureFlatData(curArray);
}
...
Thanks
Re: Using image swap in Phaser
It works, thanks =)