Jump to content

Help with collide and performance!


Recommended Posts


as I said before I'm still very new to phaser and javascript. I read tutorials and wanted to test out some basic stuff. Unfortunately even there are some problems, but I'm not sure what I'm doing wrong.


Atm you can only jump and I've choosen to collide my character with the platform. Sometimes if you start the game or jump, the character does not collide with the platform but I don't know why.


Also i tested this on my phone and fps are very low ~11 is there any way to speed things up?



var y = 0;var j = 2; // 3 Lebenvar bird;var platforms;var cursors;var heads;var score = 0;var scoreText;var life = new Array();// Create our 'main' state that will contain the gamevar mainState = {create: function() {    // Set the physics system    game.physics.startSystem(Phaser.Physics.ARCADE);    //game.physics.startSystem(Phaser.Physics.P2JS);    background2 = game.add.tileSprite(0, 0, game.width, game.cache.getImage('background').height, 'background');    platforms = game.add.group();    platforms.enableBody = true;    var ground = platforms.create(0, game.world.height - 52, 'ground');    ground.scale.setTo(4, 2);    ground.body.immovable = true;   this.bird = game.add.sprite(800, game.world.height - 250, 'bird');    game.physics.arcade.enable(this.bird);    this.bird.body.bounce.y = 0.2;    this.bird.body.gravity.y = 800;    this.bird.body.collideWorldBounds = true;    //  Head    heads = game.add.group();    for (var j = 0; j < 3; j++)    {        life[j] = heads.create(10 + j * 50, 10, 'head');    }	j = 2;    //  The score    scoreText = game.add.text(1300, 20, '0', { fontSize: '52px', fill: '#fff' });    // Call the 'jump' function when the spacekey is hit    var spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);    spaceKey.onDown.add(this.jump, this);    // Call the 'jump' function with touch    game.input.onDown.add(this.jump, this);    game.world.bringToTop(this.bird);},update: function() {		    //  Collide the bird with the platforms		    game.physics.arcade.collide(this.bird, platforms)// Debug	game.debug.text(game.time.fps || '--', 2, 100, "#00ff00");},jump: function() {    if (this.bird.body.touching.down)    		{        		this.bird.body.velocity.y = -750;			}},restartGame: function() {    this.game.state.start('menu');},};
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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