Sign in to follow this  
ogrotten

Phaser CE: sprite onClick, switching sprite between groups loses the sprite.

Recommended Posts

I'm building a card game. 6 columns (phaser groups) of 5 cards. The goal is to click the card on top and move it to the discard group. 

Currently, when i click the card, it is apparently removed from rendering. Console shows visible = true, it's new parent group shows visible = true, coords are valid, and the console shows that the new group has it and the old group has removed it. I can move the clicked card on xy, no problem. But as soon as I try to add it to a group, it disappears.

Here's the entire source on JS Fiddle. The callback function for the interaction is function tap() and lives at the bottom, of the source.

 

Share this post


Link to post
Share on other sites

Thanks for responding.

Here's the result

That's the default 800x600 screen, and you can see which one I clicked. The shown coords where it says the sprite resides is just to the right of that lone card at the bottom.

Would building a stage for it help contain things?

Share this post


Link to post
Share on other sites

Based on the spriteinfo, the 'bounds' info is different whenever I click another card. When I click the faceup card on the 2nd stack, bounds changes to x:141.5 y:160 with W and H remaining unchanged.

Is it possible that the rectangle that frames the card is moving around without the underlying spritesheet, or something like that?

Share this post


Link to post
Share on other sites

I figured out the problem.

The destination group pivot point was set to px 400,500. Then the incoming sprite had was also placed at 400,500. that means that the card was put at worldcoords of 800,1000. once I figured that out, the sprite appears where it needs to.

Thanks for the replies.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.