var id_count = 0;

Object.prototype.spawn_2d = function ()
{
    var x = document.body.getAttribute('mouse_x');
    var y = document.body.getAttribute('mouse_y');

    var id = this.getAttribute('id') ? this.getAttribute('id') + '_n_' + id_count++ : '_n_' + id_count++;

    var clone = this.cloneNode(true);
    clone.setAttribute('id', id);
    clone.setAttribute('is_active', 'true');
    clone.setAttribute('is_prefab', 'false');
    clone.setAttribute('px', x.toString());
    clone.setAttribute('py', y.toString());

    game.appendChild(clone);
}
Object.prototype.spawn_2d_px = function ()
{
    var x = document.body.getAttribute('px_x');
    var y = document.body.getAttribute('px_y');

    var id = this.getAttribute('id') ? this.getAttribute('id') + '_n_' + id_count++ : '_n_' + id_count++;

    var clone = this.cloneNode(true);
    clone.setAttribute('id', id);
    clone.setAttribute('is_active', 'true');
    clone.setAttribute('is_prefab', 'false');

    var wm = clone.style.getPropertyValue('width').replace('px', '');
    var hm = clone.style.getPropertyValue('height').replace('px', '');

    console.log(wm);

    clone.style.setProperty('left', x - (wm/2));
    clone.style.setProperty('top', y - (hm/2));

    game.appendChild(clone);
    return id;
}
Object.prototype.spawn_me = function()
{
    var id = this.getAttribute('id') ? this.getAttribute('id') + '_n_' + id_count++ : '_n_' + id_count++;
    var clone = this.cloneNode();
    
    clone.setAttribute('id', id);
    clone.setAttribute('is_active', 'true');
    clone.setAttribute('is_prefab', 'false');
    
    game.appendChild(clone);
    return clone;
}