Jump to content

PHASER 2 CAR GAME


traxtrack
 Share

Recommended Posts

Hello,


I am at my first game ever and I choose phaser2, latest CE version.

Basically I have 3 lanes and I am trying to spawn cars on these lanes, and the player must avoid crashing into them. 
The game orientation I choose is portrait.

I have a few questions that maybe you guys can help me with, if you are willing of course :D


1. I am using the default Phaser arcade Physics. Should I choose something else? I am unhappy with the collision point between the cars at the moment.
2. On Iphones and tablets I have issues with the scaling. The collision between cars is huge (I am talking about the area of collison).

I have this in the index.html 
 

	<meta name="viewport" content="width=device-width, initial-scale=1">


Then I am using this in my main js.
 

scaleRatio = window.devicePixelRatio / 3;

// Get device sizes
var w = window.innerWidth * window.devicePixelRatio;
var h = window.innerHeight * window.devicePixelRatio;

var game = new Phaser.Game(w, h, Phaser.CANVAS, '', {
  init: init,
  preload: preload,
	create: create,
  update: update,
  render: render
 });


 function init() {
   // make the game occuppy all available space, but respecting
   // aspect ratio – with letterboxing if needed
   this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
   this.game.scale.pageAlignHorizontally = true;
   this.game.scale.pageAlignVertically = true;
   this.game.canvas.style.width = '100%';
   this.game.canvas.style.height = '100%';
   this.game.scale.refresh();
 }

	// Creating the car
	car = game.add.group();
	//  We will enable physics for any object that is created in this group
  car.enableBody = true;
	// Designate the car sprite to the VAR car
	car = game.add.sprite(0 , 0, 'car');
  car.anchor.set(0.5);
  car.scale.setTo(scaleRatio, scaleRatio);
	game.physics.arcade.enable(car);

  car.x = game.world.centerX;
  car.y = game.world.height - car.height;
  // car.body.collideWorldBounds = true;
  // car.checkWorldBounds = true;
  // car.body.bounce.setTo(car.x + w/3, 0);

	// OBSTACLES
	obstacleGroup = game.add.group();
	obstacleGroup.enableBody = true;
  obstacleGroup.scale.setTo(scaleRatio, scaleRatio);

This would be it from now.

If you can pinpoint me to some articles that can help me with my car game or have any advices I would  be happy to hear them.

Thanks,

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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