Recursive objects

Mar 27, 2013 at 7:55 AM
Succeeded to compose a static object with sheets and multiple textures, I have to face the next problem: recursive objects.

My goal is to draw a portion of a map, where there could be a bunch of similar objects. Let's say that I have some trees, some rocks and some houses.

I saw that Sheetengine manages objects, to allows animation of complex goups of sheets.
Is there a way to create an instance, to be repeated elsewhere in the canvas?

I'll try to explain myself better.

Think about your example pine tree, composed by two sheets, where the silhouette of a pine tree is drawn, and placed as a cross, 90 degrees from each other.
If I have to draw 15 of them, do I have to draw each sheet (30 of them) using a function that calls the drawing commands in context of each sheet?
Or there is a way to draw the tree as an object, and then to copy it in another location for 14 times?
Coordinator
Mar 27, 2013 at 11:02 AM
What I usually do is simply define a function that creates an object, and then call that function as many times as the number of objects I want to place on the map. Like this:
    var createRocket = function(p) {
        var sheet1 = new sheetengine.Sheet({x:0,y:0,z:0}, {alphaD:90,betaD:0,gammaD:0}, {w:3,h:7});
        sheet1.context.fillStyle='#000';
        sheet1.context.fillRect(0,0,3,7);

        var obj = new sheetengine.SheetObject({x:p.x,y:p.y,z:p.z}, {alphaD:0,betaD:0,gammaD:0}, [sheet1], {w:35,h:50,relu:15,relv:10});
        return obj;
    }

    var rockets = [];
    for (var i=0;i<5;i++) {
        var rocket = createRocket({x:0,y:0,z:1000});
        rockets.push(rocket);
    }
Take a look at the source code of the Crossyards arena game as an example: https://www.crossyards.com/developers/crossyards-arena This is how multiple rockets are created as an initial step to define a pool of rockets, and them show and reposition any of the rockets when a player fires the rocket.