Jump to content

Sprite Children


G0DsDestroyer
 Share

Recommended Posts

When a parent sprite is modified, it appears to also change the values of its children, Is there a way to get around this easily?

 

I have a player and then I have a sprite that I want to place over it, and making it a child seems like the simplest way, and it works fine until I try to set the parent(player) visible = false. This results in making both the player and child disappear. However the child sprite still says its visible property is set to true.

 

The player is moving is moving along the Y axis and needs to have the child sprite follow it, and I want only the child sprite to be visible during the movement. And the child sprite is being animated as it moves as well.

 

Any help would be appreciated, just let me know if you need more information.

 

Link to comment
Share on other sites

It's pretty normal that the children are hidden : if you hide a jar of cookies, do you see cookies after ?

It's all logical, and I would say the easiest way to bypass that is to make a wrapper : create a dummy sprite (or group), add the children directly to it as well as the player.

Then, hide the player, the children will remain visible as they are no more the children of the player !

 

TLDR : PlayerContainer is the parent of the PlayerSprite and current children.

Link to comment
Share on other sites

I was afraid that was the solution, I guess I'll move on to something 'simpler' at this time, thanks for the answer.

 

So in my next question would about loading different textures instead of having separate sprites. From the tinkering I have done with phaser, it appears that any texture loaded with loadTexture() must be the same size as the previous sprite? Is this the case or ...?

 

Also, now that I have sprites the same size, and when i load the new one in, how do I get the animation to play? I add the new animation after I load the new texture, then I play the new animation, but it doesn't play as far as I can tell, or it's playing really fast, so my question is what am I doing wrong there?

 

Some code:

...create:function(){...// player animation walk cycle, played when left or right arrow is pressedplayer.animations.add('walk');...},...//This function allows player to burrow from above ground to below ground or vice versa (y axis movement). Called when B key is pressed, takes a few seconds to move up or downburrow:function(){player.animations.stop('walk');player.loadTexture('dust_cloud');player.animations.add('dust');player.animations.play('dust');...},...
Link to comment
Share on other sites

A problem I had was in my player movement function, I had player.animations.stop('walk'); when no movement keys were pressed and this was apparently stopping all animations for the player, even though I used the key for the walking animation. I solved this by only stopping the walk animation when the player is not burrowing, which is set in the burrow and the function to check the burrow which is run in the update.

 

So lingering questions: Can I load in different textures for one character that are different dimensions w/o having them be made in different locations? and Any idea why stopping the walk animation stopped the dust animation?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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