Foxhunt Posted July 28, 2014 Share Posted July 28, 2014 Hi, im trying to reset() a precreated Sprite. But it wont show up. I Create the group "bombs" and start to populate it with "bombs.createMultiple(1, 'Bomb', 0, false);".After they're created i try to reset them at the players position. Problem is they won't show up, i inspected with crome and figured out they have there position and existance state changed.They should be there some where ^^ Link and Code: https://phaser-c9-foxhunt.c9.io/examples/TestGame/index.html?_c9_id=livepreview0&_c9_host=https://ide.c9.iowindow.onload = function () { var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('Bar', 'Assets/Bar.png'); game.load.image('star', 'Assets/star.png'); game.load.spritesheet('Player', 'Assets/Ball.png', 16, 16); game.load.spritesheet('Bomb', 'Assets/Bomb.png', 8, 8); } var life = 103; var lifeText; var player; var platforms; var bombs; function create() { //Physics ON!! game.physics.startSystem(Phaser.Physics.ARCADE); //adding Background game.stage.backgroundColor = '#2d2d2d'; //Create and configure platforms a Group platforms = game.add.group(); platforms.enableBody = true; //adding ground var Ground = platforms.create(0, game.world.height - 30, 'Bar'); Ground.body.immovable = true; //pinning ground so it does not fall //add Player player = game.add.sprite(32, game.world.height - 150, 'Player'); //physics for the player on!! game.physics.arcade.enable(player); player.body.bounce.y = 0.2; player.body.gravity.y = 300; player.body.collideWorldBounds = true; player.health = life; player.scale.set(2); player.animations.add('move', null, 10, true); player.animations.play('move'); lifeText = game.add.text(16, 16, 'Life: ' + life, { fontSize: '32px', fill: '#000' }); //Create and configure Bombs Group bombs = game.add.group(); bombs.enableBody = true; bombs.scale.set(2); bombs.createMultiple(1, 'Bomb', 0, false); // for (var i = 0; i < 2; i++){ // var b = bombs.create(0, 0, 'Bomb'); // b.name = 'Bomb' + i; // b.exists = false; // b.visible = false; // } } //Well yeah drop a bomb :DD function dropBomb() { var bomb = bombs.getFirstExists(false); if (bomb){ bomb.reset(player.x + 8, player.y + 8); bomb.lifespan = 3000; } } function update() { game.physics.arcade.collide(player, platforms); var cursors = game.input.keyboard.createCursorKeys(); game.input.keyboard.addKeyCapture([ Phaser.Keyboard.SPACEBAR ]); var spaceIsDown = game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR); // Reset the players velocity (movement) player.body.velocity.x = 0; if (cursors.left.isDown) { // Move to the left player.body.velocity.x = -150; } else if (cursors.right.isDown) { // Move to the right player.body.velocity.x = 150; } // Allow the player to jump if they are touching the ground. if (spaceIsDown && player.body.touching.down) { player.body.velocity.y = -150; dropBomb(); } } function render() { //game.debug.spriteInfo(player, 5, 70); //game.debug.spriteInfo(bombs.getFirstExists(false), 5, 70); }}; Link to comment Share on other sites More sharing options...
PXBILL Posted July 28, 2014 Share Posted July 28, 2014 The bomb dont show coz you are scaling the entire group bombs, not the sprite:bombs.scale.set(2);Comment this line and will appears you can first "make" a sprite of "bomb" image and then scale it to 2 and add sprite like "key" in the createMultiple. Foxhunt 1 Link to comment Share on other sites More sharing options...
Foxhunt Posted July 28, 2014 Author Share Posted July 28, 2014 First thank you. you can first "make" a sprite of "bomb" image and then scale it to 2 and add sprite like "key" in the createMultiple. But can you explain that a little? Like in code? Cause i tried like i understood: //Create and configure Bombs Group bombs = game.add.group(); bombs.enableBody = true; var preBomb = game.add.sprite(0, 0, 'Bomb'); preBomb.scale.set(2); bombs.createMultiple(3, 'preBomb', 0, false);And i end up with Image placeholders. ^^ Results can be viewed @ the link in the 1. post. Link to comment Share on other sites More sharing options...
lewster32 Posted July 28, 2014 Share Posted July 28, 2014 (edited) The createMultiple method is just a convenience method, you don't have to use it. You could just as easily do this: //Create and configure Bombs Group bombs = game.add.group(); bombs.enableBody = true; var preBomb; for (var i = 0; i < 3; i++) { preBomb = game.add.sprite(0, 0, 'Bomb'); preBomb.scale.set(2); bombs.add(preBomb); }Or: //Create and configure Bombs Group bombs = game.add.group(); bombs.enableBody = true; bombs.createMultiple(3, 'Bomb', 0, false); bombs.forEach(function(preBomb) { preBomb.scale.set(2); });Edit: Left out bombs.add in the first example! D'oh! Edited July 29, 2014 by lewster32 Link to comment Share on other sites More sharing options...
Foxhunt Posted July 29, 2014 Author Share Posted July 29, 2014 Hi lewster32,Gonna try that. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts