Jump to content

Velocity is undefined


nothing
 Share

Recommended Posts

Console gives me this error:  TypeError: Cannot read property 'velocity' of  undefined. I don`t know what is wrong, thank you for everything.

var game = new Phaser.Game(1000, 500, Phaser.AUTO, null, {
    preload: preload,
    create: create,
    update: update,
    render: render
});
var heroname;
var conf = {
    alivethings: [
        {
            load: {
                name: "player",
                name2: "playerx",
                sprite: "ball.png"
            },
            other: {
                gravity: 1000,
                position: [400, 300],
                speed: 400,
                anchor: 0.5,
                physic: true,
                colide: true,
                gravity: 1000,
                hero: true
            }
        },
        {
            load: {
                name: "player2",
                name2: "playerx2",
                sprite: "ball.png"
            },
            other: {
                gravity: 1000,
                position: [100, 300],
                speed: 400,
                anchor: 0.5,
                physic: true,
                colide: true,
                gravity: 1000,
                hero: false
            }
        }

    ],
    objects: [
        {
            load: {
                name: "platformType1",
                name2: "platformType1s",
                sprite: "platform.png"
            },
            other: {
                position: [{
                    x: 400,
                    y: 300
                }, {
                    x: 500,
                    y: 200
                }, {
                    x: 600,
                    y: 100
                }]
            }
        }
    ]
};
//alert(conf);


function preload() {
    game.scale.scaleMode = Phaser.ScaleManager.NO_SCALE; // canvas se nepřispůsobuje obrazovce
    game.scale.pageAlignHorizontally = true; //nemám ponětí
    game.scale.pageAlignVertically = true; // nemám ponětí
    game.stage.backgroundColor = '#eee'; // barva canvasu
    startinitpreload()

};

function create() {
    game.physics.startSystem(Phaser.Physics.ARCADE);
    startinitcreate();

}


function update() {
    heroname.body.velocity.x = -250


}

function render() {

}

var initpreloadplatform = function (val3) {
    game.load.image(val3.name2, val3.sprite);
    alert("sad")
}

function startinitpreload() {
    var localx = conf.alivethings;
    for (i = 0; i < localx.length; i++) {
        localx[i].load.name = new initpreload(localx[i].load);
    }
    var localy = conf.objects;
    for (a = 0; a < localy.length; a++) {
        localy[a].load.name = new initpreloadplatform(localy[a].load);
    }
}
var initpreload = function (val1) {
    game.load.image(val1.name2, val1.sprite);
}

function startinitcreate() {
    //  game.physics.startSystem(Phaser.Physics.ARCADE);
    var localx = conf.alivethings;
    var localy = conf.objects;
    for (i = 0; i < localx.length; i++) {
        localx[i].load.name = new initcreate(localx[i]);
        if (localx[i].other.hero == true) {
            heroname = localx[i].load.name;
        }
    }
    for (l = 0; l < localy.length; l++) {
        alert(l);
        localy[l].load.name = new initcreateplatform(localy[l]);
        if (localy[l].other.hero == true) {
            heroname = localy[l].load.name;
        }
    }
}
var initcreateplatform = function (val4) {
    var valss = val4.load.name;
    valss = game.add.physicsGroup();
    for (i = 0; i < val4.other.position.length; i++) {
        valss.create(val4.other.position[i].x, val4.other.position[i].y, val4.load.name2);
    }

}
var initcreate = function (val2) {

    var vals = val2.load.name;
    vals = game.add.sprite(val2.other.position[0], val2.other.position[1], val2.load.name2);
    vals.anchor.set(val2.other.anchor);
    if (val2.other.physic == true) {
        alert()
        game.physics.enable(vals, Phaser.Physics.ARCADE);
        vals.body.gravity.y = val2.other.gravity;
        vals.body.collideWorldBounds = true;
        vals.body.bounce.set(1);
        game.physics.arcade.enable(vals);
    }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...