Stonekeeper

Anchor emitter to sprite

Recommended Posts

On the webpage it talks about attaching an emitter to a sprite so that you can create a "jet". Is this done via groups? I've setup a player sprite and all my controls currently work on that. If creating a group is the answer, should a refactor be as simple as changing <sprite>.body to <group>.body?

 

Thanks. 

Share this post


Link to post
Share on other sites

Looks like the particles are also affected by the rotation of the parent object. Not really what I was looking for. If there is no way to detach the particle from the transformation pipeline then I may just have to calculate emitter position independently using cos/sin.

Share this post


Link to post
Share on other sites

I would not add the emitter to a sprite with addChild. You can't really control if the emitter is going to render above or beneath the sprite texture. You should place a simple position syncing in your update loop.

//This update function is provided by your current stateupdate: function(){    emitter.x = sprite.x    emitter.y = sprite.y} 

That's it.

By the way, you could also apply a counter rotation to the emitter in your sprite's update function. Something like this. This works as long as your sprite is not inside another object that is rotated itself. 

//inside your sprite updateemitter.rotation = -this.rotation

But why would you do it like this? Use the manual sync mentioned above instead!

Share this post


Link to post
Share on other sites

Your are talking about the situation that the emitter is not a child of the sprite aren't you ? The emitter inherits from group. Every particles is a child of the emitter. As long as the emitter is behind the sprite all the particles are behind it too.  The emitter itself is a display object and can be brought in the correct display order with a #swap, a #bringToTop call or whatever you can use to modify the order.

Share this post


Link to post
Share on other sites

Hi, may I use this post by George (

//This update function is provided by your current stateupdate: function(){    emitter.x = sprite.x    emitter.y = sprite.y} 

)

I have a group of missile and I need each missile be follow by my particles.

 

Thanks a lot.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.