0

For every level, there is an array of coordinates that I want to create new instances based on. I am wondering how to go about doing this. Here's what I have so far.

    function levelDots(level){
        var renderLevel = {
                    1: [(100, 100), (200, 200)], //not sure if this is correct,  e.g (100, 100) would correspond to (x,y)
                    2: [(50,50), (75,75)]
                }


        renderLevel[level].each(function(){ //not sure what to put inbetween function()
            dots.push(new dot(x,y))
        });

    }
0

1 Answer 1

1

(x, y) returns y in javascript, use an array [100, 100] or object {x: 100, y: 100} to represent the value.

Example:

function levelDots(level) {
    var renderLevel = {
        level1: [
            [100, 100],
            [200, 200]
        ],
        level2: [
            [50, 50],
            [75, 75]
        ]
    };
    return renderLevel[level].map(function (el) {
        return new dot(el[0], el[1]);
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.