Jump to content

Performance problems with Phaser


ferat
 Share

Recommended Posts

Hello guys,

 

I'm making my first game using Phaser, but i have a problem.

 

The idea is: the player guide a yellow monster to eat the food taht falls from the screen. When the player eat, should immediately drop a new food.

 

The problem is that sometimes the food takes to fall. I changed several things in the code, but got no result.

 

Thank you for your attention

 

Play de game:

http://tiagosilvapereira.esy.es/Scroller/

window.onload = function(){	var width = navigator.isCocoonJS ? window.innerWidth : 640,        height = navigator.isCocoonJS ? window.innerHeight : 960;	game = new Phaser.Game(width, height, Phaser.AUTO, '',	{		preload: loadAssets,		create: createScenario,		update: updateGame	});}var score = 0;var life = 100;var life_dec = 5;var food_velocity = 400;var food_position_x = 0;var food_value = 5;var left=false;var right=false;function loadAssets(){	game.time.advancedTiming = true;	game.load.image('background', 'assets/background.png');	game.load.image('player', 'assets/player.png');	game.load.image('food', 'assets/food.png');	game.load.spritesheet('btn_left', 'assets/btn_left.png', 64, 64);	game.load.spritesheet('btn_right', 'assets/btn_right.png', 64, 64);}function createScenario(){	//if (!game.device.desktop){ game.input.onDown.add(gofull, this); }	//game.device.cocoonJS = true;	//game.device.android = true;	game.input.maxPointer = 1; //Desabilita o multitoque        game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;        game.scale.pageAlignHorizontally = true;        game.scale.pageAlignVertically = true;        game.scale.setScreenSize(true);			game.physics.startSystem(Phaser.Physics.ARCADE);		cursors = game.input.keyboard.createCursorKeys();	    buttonleft = game.add.button(0, 900, 'btn_left', null, this, 0, 1, 0, 1);    buttonleft.fixedToCamera = true;    buttonleft.events.onInputOver.add(function(){left=true; right = false;});    buttonleft.events.onInputOut.add(function(){left=false;});    buttonleft.events.onInputDown.add(function(){left=true; right = false;});    buttonleft.events.onInputUp.add(function(){left=false;});    buttonright = game.add.button(576, 900, 'btn_right', null, this, 0, 1, 0, 1);    buttonright.fixedToCamera = true;    buttonright.events.onInputOver.add(function(){right=true; left = false;});    buttonright.events.onInputOut.add(function(){right=false;});    buttonright.events.onInputDown.add(function(){right=true; left = false;});    buttonright.events.onInputUp.add(function(){right=false;});		createBackground();	food = game.add.group();	food.enableBody = true;	createPlayer();	createFood();	scoreText = game.add.text(10, 10, 'Score: 0', {font: "20px Arial", fill: "#ffffff", align: "left"});	lifeText = game.add.text(10, 50, 'Life: 100', {font: "20px Arial", fill: "#ff7700", align: "left"});	game.time.events.loop(2000, decLife, this);}// Atualiza o jogo - 60fpsfunction updateGame(){	lifeText.text = 'Life: ' + life;	if(life <= 0){		var text = game.add.text(game.camera.width / 2 - 100, 								 game.camera.height / 2,								 "GAME OVER",								 {								 	font: "30px Arial",								 	fill: "#ff0044",								 	align: "center"								 });	}	player.body.velocity.x = 0;	moveFood(food_velocity);	game.physics.arcade.overlap(player, food, overlapFood);	if (cursors.left.isDown || left == true){		player.body.velocity.x = -1500;	}else	if (cursors.right.isDown || right == true){		player.body.velocity.x = 1500;	}	game.debug.text(game.time.fps || '--', 600, 14, "#00ff00");}function createBackground(){	game.add.sprite(0, 0, 'background');}function createPlayer(){	player = game.add.sprite(game.world.centerX - 16, game.world.height - 200, 'player');	game.physics.arcade.enable(player);	player.body.collideWorldBounds = true;}function overlapFood(){    food01.body.position.y = 0;    randomFoodPos();    food01.body.position.x = food_position_x;    if(food_velocity < 2500){    	    	food_velocity += 10;    }    if(life < 100){    	life += food_value;    }else{    	life = 100;    }    score++;    scoreText.text = 'Score: ' + score;}// Cria as plataformasfunction createFood(){	randomFoodPos();	food01 = food.create(food_position_x, 0, 'food');}function moveFood(speed){	food01.body.velocity.y = speed;	if(food01.body.position.y >= 960){ 			    food01.body.position.y = 0;			    randomFoodPos();	    food01.body.position.x = food_position_x;		}}function randomFoodPos(){	food_position_x = game.rnd.integerInRange(32, game.world.width - 32);}function decLife(){	// Decrementa a vida do player	if(life > 0){		life -= life_dec;	}else life = 0;}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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