Jump to content

addChild without inheriting properties


Nek0
 Share

Recommended Posts

this is very hard to explain, but i essentially have a bunch of sprites holding spears, and seek to have their range beyond what the player can hit from the front. i want the hit box of the "spearman" to be smaller than its weapon (ie: sprite.scale.set(.5, 1)), and believe the best way to do this is to add a second child sprite which is smaller than the original sprite as the hittable body. trouble is, the children inherit the parent's properties, which is not wanted. another way is to make the ORIGINAL body smaller and add a larger child sprite as the spear, but this creates problems with horizontal flip alignment when the spearmen reach the edge of platforms and turn around.

put another way, say you have ten sprites in a group all added via createFromObjects. then you want ANOTHER set of sprites to follow these sprites in tandem. this is perhaps usually done with some form of forEach and addChild implementation. the problem is that addChild always makes the child inherit the parent's properties, which is not desired. any way to have the child follow the parent while retaining a different scale/alpha/etc than the parent? any examples on how to do this would be appreciated.

Link to comment
Share on other sites

  • 2 weeks later...

well, i found a quasi-solution that doesn't involve addChild at all. instead it involves forEachAlive and detecting whether or not the player is in FRONT of a spear guy. if so, the player's attacks don't work against them; only from behind. i'd provide an example, but this seems a pretty insular issue.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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