Jump to content

Very basic troubles with phaser


bonsai
 Share

Recommended Posts

Hi! I'm two days with phaser and it's pretty cool :D  but I have two little problems I don't know how to solve... so please if anybody know what am I losing I will be very apreciated :)

 

This creates 2 enemies sprites and adds to the group. But when I run the js just 1 is moving. If I change the numer of the iterations is always the same, the last one is always like velocity.y = 0 (but sprite animated)

    enemies = game.add.group();    for (var i = 0; i < 2; i++)    {        var enemy = enemies.create(i * 60, 0, 'enemy');        enemy.body.collideWorldBounds = false;        enemy.outOfBoundsKill = true;            enemy.body.immovable = true;        enemy.animations.add('right', [2, 3], 10, true);        enemy.animations.play('right');        enemy.body.velocity.x = 100;    }

The other one is when I hit one enemy I want it to chance the sprite and become other one, but I want it in the same x,y and velocity, but it just turn to the other sprite and stay in another x-y point I dont know where it takes from and without animate:

var cooler = coolers.getFirstDead();cooler.centerOn(enemy.x,enemy.y);cooler.reset(enemy.body.velocity.x,enemy.body.velocity.y);enemy.kill();score += 10;scoreText.content = 'Puntuación: ' + score;

Thanks you very much ;)

 

pandaNinja.html

Link to comment
Share on other sites

Trouble with moving enemy : 

I would like to help with problem  2, but there are no attached sprites.

function createEnemy(group,i){var enemy = group.create(i * 60, 0, 'enemy');		//enemies.callAll('centerOn', '', game.world.width/3, game.world.height/3);		//enemies.setAll('x',game.world.width/3);		//enemies.setAll('y',game.world.height/3);		//enemy = game.add.sprite(game.world.width/3, game.world.height/3, 'enemy');		//enemies.setAll('colliderWorldBounds', false);		enemy.body.collideWorldBounds = false;		//enemies.setAll('outOfBoundsKill', true);		enemy.outOfBoundsKill = true;			//enemies.setAll('body.immovable', true);		enemy.body.immovable = true;		//enemies.callAll('animations.add', 'animations', 'movimiento', [2,3], 10, true);		enemy.animations.add('right', [2, 3], 10, true);		//enemies.callAll('animations.play', 'animations', 'movimiento');		enemy.animations.play('right');		//enemies.setAll('body.velocity.x', 100);		enemy.body.velocity.x = 100;}	for (var i = 0; i < 5; i++)    {        createEnemy(enemies,i);	}
Link to comment
Share on other sites

It is a copy paste error.

 

When you are making your "cooler" objects, you are calling functions on the last enemy you created.

    coolers = game.add.group();    for (var i = 0; i < 12; i++)    {        var cooler = coolers.create(0, 0, 'cooler','',false);        //These lines should be "cooler.", not "enemy."...        enemy.body.collideWorldBounds = false;        enemy.outOfBoundsKill = true;            enemy.body.immovable = true;        enemy.animations.add('right', [2, 3], 10, true);        enemy.animations.play('right');        enemy.body.velocity.x = 0;    }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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