codevinsky

Members
  • Content Count

    212
  • Joined

  • Last visited

  • Days Won

    5

Posts posted by codevinsky


  1. We all love the forums, but sometimes you just need some quick help or discussion. 

     

    I've created the #phaserio channel on freenode.

     

    If you've got irc already up and running, just hop on to freenode (chat.freenode.net) and join #phaserio.

     

    If you don't, you can use the web irc client for freenode:

    1. hit this link: http://webchat.freenode.net/ 

    2. put your forum handle in the nickname box

    3. put #phaserio in the channel box.

     

     

    See you guys there.


  2. Cross posted from here.
     
    I've got a prefab class that inherits from Group.
     

    var PipeGroup = function(game, x, y, collisionGroup, collidesWith) {Phaser.Group.call(this, game);var topPipe = this.create(0,0,'pipes');topPipe.physicsEnabled = true;topPipe.body.kinematic = true;topPipe.body.setRectangle();topPipe.body.setCollisionGroup(collisionGroup);topPipe.body.collides(collidesWith);this.x = x;this.y = y,}; PipeGroup.prototype = Object.create(Phaser.Group.prototype);PipeGroup.prototype.constructor = PipeGroup;

    And in my main game's create function:
     

    create = function() {  ..        this.playerCG = game.physics.createCollisionGroup();  this.pipeCG = game.physics.createCollisionGroup();   // add our player to the stage  this.player = this.add.sprite(game.world.width/3,220,'bird');   // enable physics on our player  this.player.physicsEnabled = true;    // add our player to the player collision group  this.player.body.setCollisionGroup(this.playerCG);  this.player.body.collides([this.pipeCG], this.death, this);  ..  game.time.events.loop(Phaser.Timer.SECOND,this.generatePipes, this);}

    and generatePipes looks like:
     

    generatePipes: function() {  var pipeY = game.rnd.integerInRange(-120,120);  var pipes = new PipeGroup(game,game.world.width + 32, pipeY, this.pipeCG, this.playerCG);  this.player.body.collides([this.pipeCG], this.death, this);}

    However, the player is never colliding with the pipes.
     
    Can you modify a collision group after the create phase of a state?

    I'm a bit at a loss to figure out why this doesn't work.


  3. I have a similar question:

    I've got a prefab class that inherits from Group.

    var PipeGroup = function(game, x, y, collisionGroup, collidesWith) {	Phaser.Group.call(this, game);	var topPipe = this.create(0,0,'pipes');	topPipe.physicsEnabled = true;	topPipe.body.kinematic = true;	topPipe.body.setRectangle();	topPipe.body.setCollisionGroup(collisionGroup);	topPipe.body.collides(collidesWith);	this.x = x;	this.y = y,};PipeGroup.prototype = Object.create(Phaser.Group.prototype);PipeGroup.prototype.constructor = PipeGroup;

    And in my main game's create function:

    create = function() {  ..        this.playerCG = game.physics.createCollisionGroup();  this.pipeCG = game.physics.createCollisionGroup();  // add our player to the stage  this.player = this.add.sprite(game.world.width/3,220,'bird');  // enable physics on our player  this.player.physicsEnabled = true;    // add our player to the player collision group  this.bird.body.setCollisionGroup(this.playerCG);  this.bird.body.collides([this.pipeCG], this.death, this);  ..  game.time.events.loop(Phaser.Timer.SECOND,this.generatePipes, this);}

    and generatePipes looks like:

    generatePipes: function() {  var pipeY = game.rnd.integerInRange(-120,120);  var pipes = new PipeGroup(game,game.world.width + 32, pipeY, this.pipeCG, this.playerCG);  this.player.body.collides([this.pipeCG], this.death, this);}

    However, the player is never colliding with the pipes.

     

    What gives?


  4. I've got a ground TileSprite that is used to show a running ground beneath the player:

    create: function() {   ...  this.ground = game.add.tileSprite(0,400, 335,112,'ground');  ...}, update: function() {  ...  this.ground.tilePosition.x -= 5;  ...}

    I want a collision between the player (which has physicsEnabled on it) and the ground. 

     

    How can I achieve this? 

    Do I need to create a dummy sprite that has phsyicsEnabled on it that lays over the ground tileSprite, or can I collide with the ground tileSprite?


  5. You could use

    var distance = game.physics.distanceBetween(player1, player2); 

    and then set the world scale based on that distance with

    game.world.scale.setTo(someXScale, someYScale);

    Basically, you'd be using the scale to zoom. The larger the scale, the closer the zoom. Because you'll be following two players, it's probably easier to do it this way than to have the camera itself try to follow each player. You could also set the camera's x position to the halfway point between the two players so that they are always exactly in the same place on screen.

     

    Just my two cents.