Description

Allows you to change the parameters of an element in the construction layers

Usage

Parameters

  • callback {Function}

    Callback function called before the introduction of an element. Returns the same object with different values ??to change the element. Two parameters :

    • {CanvasEngine.Element} The element is created and ready to be displayed on the layer
    • {Object} the parameters of the element :

      { id: {String} (filename), regX: {Integer}, regY: {Integer}, x: {Integer}, y: {Integer}, rotate: {Integer}, scaleX: {Float}, scaleY: {Float} }

Example

In the method "ready" of current scene :

var gleed = canvas.Gleed2d.new();
gleed.ready(function() {

});
gleed.change(function(el, params) {
    console.log(params.x, params.y); // Change Position X and Position Y
    return {
        x: params.x + 5 // Change the position x of the element.
    };
});
gleed.load(this, element, "data");

Dividing the image of the element :

var gleed = canvas.Gleed2d.new();
gleed.ready(function() {

});
gleed.change(function(el, params) {
    return {
        img: [0, 0, 42, 42, 0, 0, 42, 42] // == drawImage(image, 0, 0, 42, 42, 0, 0, 42, 42);
    };
});
gleed.load(this, element, "data");

Not allow drawing on the element

var gleed = canvas.Gleed2d.new();
gleed.ready(function() {

});
gleed.change(function(el, params) {
    el.drawImage("other_img");
    return {
        draw: false
    };
});
gleed.load(this, element, "data");

Discussion