How to set IsoCharacter as a template and then clone it?
mberube

Hi! 

I'm tryng to set as a template an IsoCharacter sceneObject not marked as 'add To Scene' from Wade IDE.

First the sceneObject seems to be added and visible anyway.

The cloned object is visually copied at the right position, but the setDestination() is not working:

  • the 'template' object is the one moving
  • the behavior is not working for the cloned object.

Is there a way to mannually create an IsoCharacter and set it to setTemplate(true) before adding it to the scene?

 

//Code example

var isoObj = wade.getSceneObject('isoObj');
isoObj.setAsTemplate(true);

newObj = isoObj.clone();
newObj.setPosition(spawnPosition);

newObjBehavior = newObj.getBehavior('IsoCharacter');

wade.addSceneObject(newObj, true);

newObjBehavior.setDestination(nextFreeTile);

Thanks a lot I really appreciate your iso plugin!

 

 

All 2 Comments
Gio

Hi

While your approach above makes a lot of sense, unfortunately it won't work because currently isometric objects do not work in the exact same way as regular scene objects. I know this can be very confusing and we are going to change this for version 4 of WADE.

At present, the best way to achieve what you want is to create a tileset, where your isometric character is a tile. You can assign it any behaviors, in your case you would give it the IsoChacater behavior, as part of the tile definition (you can do this in the tile editor, or by editing the .its file manually, which is just json).

Once you have your tileset with your character in it, you want to load the tileset as json. If you are using the editor, you can do somethin like this

If you do that, your tileset data will be available in wade.app.characters while the game is running.

This then allows you to do things such as

wade.iso.createObject(wade.app.characters.tiles[0], {x: 2, z: 3});

 

mberube

WOW! Thanx for the quick reply.

Yes i tried to managed IsoCharacter object like other sceneObjects, but iso objects do not manage template.

 

Here is a snippet of what I integrated last night for the benefit of others:

 

 

this.load = function()
{
    
    //Load iso characters file data
    wade.loadJson('tilesets/characters/char1/char1.its', null, self.loadJsonCallback, false, self.loadJsonErrorCallback);
    wade.loadJson('tilesets/characters/char2/char2.its', null, self.loadJsonCallback, false, self.loadJsonErrorCallback);
}

/************************************** 
* loadJson callbacks
**************************************/
this.loadJsonCallback = function(data)
{
    isoCharacterList.push({"name": data.tiles[0].name, "data": data});
    console.log("loadJsonCallback", isoCharacterList);
}
this.loadJsonErrorCallback = function(error)
{
    console.log("loadJsonErrorCallback", error);
}



/************************************** 
* Set Current Character
**************************************/
this.setCurrentCharacter = function()
{
    
    //Set character on random spawnpoint
    var defaultSpawnCoord = GP.rules.spawnCoord.char[Math.floor(Math.random() * GP.rules.spawnCoord.char.length)];

    //Create Iso Character Scene Object from loaded .its JSON data and random spawn position
    var IsoData = isoCharacterList.filter(function(item) { return item.name === currentCharacterID; });
    
    C = wade.iso.createObject(IsoData[0].data.tiles[0], defaultSpawnCoord, null);

   CB = C.getBehavior('IsoCharacter'); // Chracter iso behavior
    CB.movementSpeed = movementSpeed; //Default is 160
    CB.variationProbability = GP.char.variationProbability;
    //Default movement and direction
    CB.setDirection(C_dir);
    CB.setMovementType('diagonal');

    //Bind event to Character
    wade.addEventListener(C, 'onUpdate');
    wade.addEventListener(C, 'onMoveComplete');
    C.onUpdate = function()
    {
        if(isGameStarted){
            wade.app.onCharacterUpdate();
        }
    };
    C.onMoveComplete = function()
    {
        wade.app.onCharacterMoveComplete();
    };

}

 

Post a reply
Add Attachment
Submit Reply
Login to Reply