Jump to content

Brick Breaker game issues!


Get_Bentley
 Share

Recommended Posts

Ok everyone so I am doing a brick breaker type game, I am creating my own sprites for the bricks and for the paddle. So my first question is if I want the bricks to crumble when colliding with the ball what would be the best way to do this? Would it be best to have two separate .png files with the two images and tween them? Or would it be best to have it all in one sprite sheet and use some type of animation when the collision is detected?

 

Second issue I am having is when I scale either the bricks or the paddle the collision box is way out of whack. Is there a way to keep the collision type anchored to the sprite size?

 

Thanks everyone! Appreciate any help!

Link to comment
Share on other sites

Both of your ideas are valid; it depends how 'dynamic' you want the crumbling to be - if you had two broken halves of brick, you could apply some physics, gravity, velocity and angular velocity to them modified with random values to make them fly off somewhat unpredictably. On the other hand you could create cool animations manually and have the animation play. Another way would be to have chunks of brick added to a particle system and do a particle 'burst' a bit like this example. You could even do a mixture of any of these, and have a shattering/exploding animation that sends bits of brick flying out.

 

As for your other issue, scaling sprites should scale their collision boundaries. You may want to call game.body.debug(sprite) in your render function to see what's going on with your physics bodies.

Link to comment
Share on other sites

Both of your ideas are valid; it depends how 'dynamic' you want the crumbling to be - if you had two broken halves of brick, you could apply some physics, gravity, velocity and angular velocity to them modified with random values to make them fly off somewhat unpredictably. On the other hand you could create cool animations manually and have the animation play. Another way would be to have chunks of brick added to a particle system and do a particle 'burst' a bit like this example. You could even do a mixture of any of these, and have a shattering/exploding animation that sends bits of brick flying out.

 

As for your other issue, scaling sprites should scale their collision boundaries. You may want to call game.body.debug(sprite) in your render function to see what's going on with your physics bodies.

 

Thanks so much for the reply, I actually figured most of it out last night. The reason the collision body was separate from the sprite itself was because I didnt realize when creating a sprite from scratch and saving it to a png file that phaser uses the whole file as a sprite ( noob mistake ). So I just edited the png file itself to be as large as the sprite that was drawn and it fixed the collision issues.

 

I also tinkered with a particle burst method as you previously mentioned, I have it so when the ball and paddle collide it does a particle burst, but when trying to apply a burst to when a brick dies it would not work, is there something special you have to do to have multiple emitters in a game? Do they need to be in a group?

 

Once again thanks for the reply man!

Link to comment
Share on other sites

Yeah unfortunately im at work right now but maybe I can explain. Thanks again for the help really appreciate it.

So this would be an example of the code

 

// in create

 

emitter = game.add.emitter(0, 0, 100);

    emitter.makeParticles('particle');
    emitter.gravity = 200;

    game.input.onDown.add(particleBurst, this);

 

 

 

emitterBlue = game.add.emitter(0, 0, 100);

    emitterBlue.makeParticles('blueParticle');
    emitterBlue.gravity = 200;

    game.input.onDown.add(particleBurstBlue, this);

 

 

// in game state

 

particleBurst: function(pointer) {

 emitter.x = pointer.x;
    emitter.y = pointer.y;

 

emitter.start(true, 2000, null, 10);

}

 

particleBurstBlue: function(pointer) {

 

 emitterBlue.x = pointer.x;
    emitterBlue.y = pointer.y;

 

emitterBlue.start(true, 2000, null, 10);

}

 

 

the error I was receiving was something like cannot use start of undefined. Although I did define emitterBlue in the create function.

 

 

Hope that makes sense. Thank you!

Link to comment
Share on other sites

If you're defining emitter and emitterBlue without the 'var' keyword, they're global and may not be behaving as expected. I'd need to see the whole of the code but I'm sure it's a simple case of the emitter not being defined when being called - the undefined error is telling you this; that it cannot call a function on an object which doesn't exist.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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