Jump to content

Particles containment in sprite or something else


lukaMis
 Share

Recommended Posts

Hi

 

Is there a way of containing particles inside sprite or something like that?

Lets say that I have a png of box or some other container. Is there a way to make particles inside that specific object? And than tell them to stay inside bounds of that object?

 

Ex:

 

makeParticles(keys, frames, quantity, collide, collideMyObjectBounds)

 

instead

 

makeParticles(keys, frames, quantity, collide, collideWorldBounds)

 

tnx

Luka

 

Link to comment
Share on other sites

The above solution probably won't work as intended as collision with anything other than world bounds is done from the outside - if you have an object inside another and attempt to do collision, it will just fly out of the object ignoring the boundaries. This isn't a problem with a neat solution currently; you could surround the emitter with four rectangles to create invisible walls though it would be much more efficient if you were to replicate the way the world bounds checking happens with an arbitrary rectangle per emitter - this will likely require a bit of hacking!

Link to comment
Share on other sites

Hi

 

@lewster32 Hmm that sound like an interesting idea but i am not sure if i am up to it. I got an idea for a workaround that is like this:

Canvas element will be as big as i need my object to be. This will be game world essentially. Particles will live inside. 

I will than overlay canvas element in html markup with div containing png sort of masking it. To the end user it will appear as though particles are inside object and i will be able to use collideWorldBounds. :)
I guess in my case this will be the way to go since canvas element can't have round corners but container that i will use has. It would look weird if particles would follow curvature of my container. Now i will be able to get away with it.  

 

*This is first time i am using Phaser so i guess things could be done differently but i am learning...

Link to comment
Share on other sites

I fear your method is very inefficient and will almost certainly be problematic. For what it's worth, the collideWorldBounds flag makes each of the particles run the Phaser.Physics.Arcade.Body.checkWorldBounds method during preupdate. As you can see it's a simple and fast bounds check which you could adapt and add to a custom extended particle object. You could then just set emitter.particleClass = MyCustomParticle and have your particles behave as needed.

 

Speaking from much personal experience of resisting delving deeper into frameworks and getting things working 'the easy way', I implore that you try to solve the problems presented rather than find a way around them. It will make you a better programmer and the results will be worth it. Phaser is very well constructed, modular and commented, and it doesn't take a lot of effort to uncover how things work and adapt/extend them to your specific needs. Plus the excellent community here are always available to help you out if you get stuck!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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