Jump to content

CollideWorldBounds make the sprite don`t move


javi156
 Share

Recommended Posts

I`m doing a little game but when i set collideworldbounds to the sprite and this touch de down bound it can´t jump anymore.

How can i repair this?

 

This is my code:

// Inicializa Phaser y crea un canvas de 720x480 pxvar game = new Phaser.Game(720, 480, Phaser.AUTO, 'game_div');// Crea un nuevo 'main' que contendra el juegovar main_state = {//Variable para el spritesheet//    preload: function() { 		// Funcion llamada antes de las demas para cargar los graficos		//Color de fondo		this.game.stage.backgroundColor = '#E1EDF2';		//Graficos del juego		this.game.load.spritesheet('pingu', 'assets/animapingu.png',95,84,5);		this.game.load.image('ice', 'assets/hielo.png');		this.game.load.image('limite', 'assets/limites.png');    },    create: function() {     	// Funcion despues del preload para programar el juego    	//Dibuja el grafico en pantalla    	this.pingu = this.game.add.sprite(100, 240, 'pingu');    	this.pingu.body.collideWorldBounds = true;    	//Añade una animacion al grafico    	this.pingu.animations.add('inflar',[0,1,2,3,4,4,4,4,4,3,2,1,0],20,false);    	//Creacion del suelo    	//Crea gravedad al pinguino    	this.pingu.body.gravity.y = 1000;    	//Boton espacio para saltar    	var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);    		space_key.onDown.add(this.jump, this);    	//Bucle para lanzar hielos     	game.time.events.loop(Phaser.Timer.SECOND * 2, this.add_hielo, this);    		    },        update: function() {		// Funcion llamada 60 veces por segundo		//Animacion de movimiento		if (this.pingu.angle < 20){			this.pingu.angle +=1;		}    },    //Funcion saltar    jump: function(){    	this.pingu.body.velocity.y = -400;    	//Animacion    	var animation = this.game.add.tween(this.pingu);    	animation.to({angle: -20}, 100);    	animation.start();     	//Hacer spritesheet para animacion en salto    	this.pingu.animations.play('inflar');    },    add_hielo: function(){    	var hielo = this.game.add.sprite(719, Math.floor(Math.random()*479)+1, 'ice')    	hielo.body.velocity.x = -200;    },};// Añade e inicializa el 'main' para empezar el juegogame.state.add('main', main_state);  game.state.start('main'); 
Link to comment
Share on other sites

CollideWorldBounds avoid jumping because it seems that it blocks any movement when touching a world limit.

I don't know if this is voluntary from Phaser Devs or there is any reason to this behaviour, but this worked for me : Check manually if your sprite body is beyond world limits, and avoid movement if so.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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