lukaMis Posted June 10, 2014 Share Posted June 10, 2014 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) tnxLuka Link to comment Share on other sites More sharing options...
GNUton Posted June 11, 2014 Share Posted June 11, 2014 Hi have a look at the example http://examples.phaser.io/_site/view_full.html?d=particles&f=collision.js&t=collision in the update function you wanna set a second argument for the collide(emitter, array_of_objs_or_group). function update() {game.physics.arcade.collide(emitter); } Link to comment Share on other sites More sharing options...
lewster32 Posted June 11, 2014 Share Posted June 11, 2014 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 More sharing options...
lukaMis Posted June 12, 2014 Author Share Posted June 12, 2014 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 More sharing options...
lewster32 Posted June 12, 2014 Share Posted June 12, 2014 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! lukaMis 1 Link to comment Share on other sites More sharing options...
lukaMis Posted June 13, 2014 Author Share Posted June 13, 2014 @lewster32 Tnx.This must be one of the best or best even advice i was ever given. I will bite the bullet and try to do this the proper way. Link to comment Share on other sites More sharing options...
lewster32 Posted June 13, 2014 Share Posted June 13, 2014 Good man! We're with you every step of the way Link to comment Share on other sites More sharing options...
Recommended Posts