Unable to use binaries instead of json for pixi runtimes

Discuss issues pertaining to the various game/web runtimes of Creature here.
Post Reply
shivaaz
Posts: 4
Joined: Tue Jul 04, 2017 1:39 pm

Unable to use binaries instead of json for pixi runtimes

Post by shivaaz » Tue Jul 04, 2017 1:53 pm

I referred the following link for implementation

http://www.kestrelmoon.com/creaturedocs ... times.html

My code
var actual_data = CreatureModuleUtils.LoadCreatureFlatData(game.cache.getBinary('myFlatDataBinary.bin'));

Its displaying the below error
Uncaught TypeError: Cannot read property 'getBinary' of undefined

Any help appreciated

chong
Posts: 693
Joined: Thu Feb 19, 2015 2:21 am

Re: Unable to use binaries instead of json for pixi runtimes

Post by chong » Tue Jul 04, 2017 4:05 pm

Hello,

The API for PixiJS might have changed, that is why their game object does not have the getBinary() function.
You don't actually have to use the game object cache to retrieve binary data, you can use regular JS to get a response/get a binary array from the flat data. After that, just pass it into the LoadCreatureFlatData function.

Cheers

shivaaz
Posts: 4
Joined: Tue Jul 04, 2017 1:39 pm

Re: Unable to use binaries instead of json for pixi runtimes

Post by shivaaz » Wed Jul 05, 2017 8:50 am

Thanks for the help.

I tried using regular JS to get the binary text as you said.
But, again there's an error in library file
TypeError: flat_mesh is null CreatureMeshBone.js:2994:3

This is my code
var byteArray=[];
var xobj = new XMLHttpRequest();
xobj.open('GET', 'animations/hey.bin', true);
xobj.overrideMimeType('text/plain; charset=x-user-defined');
xobj.responseType = '';
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
var response1 = xobj.responseText;
for (var i = 0; i < xobj.responseText.length; ++i) {
byteArray.push(xobj.responseText.charCodeAt(i) & 0xff)
}

actual_data = CreatureModuleUtils.LoadCreatureFlatData('byteArray');

new_creature = new Creature(actual_data, true);
new_animation_1 = new CreatureAnimation(actual_data, "idle", true);

chong
Posts: 693
Joined: Thu Feb 19, 2015 2:21 am

Re: Unable to use binaries instead of json for pixi runtimes

Post by chong » Wed Jul 05, 2017 3:05 pm

Hello,

Is this the actual line you wrote:

Code: Select all

actual_data = CreatureModuleUtils.LoadCreatureFlatData('byteArray');
Just want to confirm with you. Because it looks like you should be passing in the byte array, not a string which you are doing.
The string 'byteArray' does not contain the binary data.

Cheers

shivaaz
Posts: 4
Joined: Tue Jul 04, 2017 1:39 pm

Re: Unable to use binaries instead of json for pixi runtimes

Post by shivaaz » Fri Jul 07, 2017 5:59 am

Thanks for the help.

Can you give an example of code if possible?

Thanks again

chong
Posts: 693
Joined: Thu Feb 19, 2015 2:21 am

Re: Unable to use binaries instead of json for pixi runtimes

Post by chong » Fri Jul 07, 2017 6:27 am

Hello,

This is more of a general JavaScript question ( not really Creature related ). You want to know how to load a Uint8Array from some data online.
I found this link for you, hope it helps:

https://developer.mozilla.org/en-US/doc ... inary_Data

After you get the array, you pass it into the LoadCreatureFlatData function.

shivaaz
Posts: 4
Joined: Tue Jul 04, 2017 1:39 pm

Re: Unable to use binaries instead of json for pixi runtimes

Post by shivaaz » Fri Jul 07, 2017 4:46 pm

Thank you so much for the help Chong!

I was finally able to do it :)

Post Reply