Jump to content

Overlap Between a Group and Sprite with Alpha


Pbaroque18
 Share

Recommended Posts

Hello everyone,

 

Context:

I'm supposed to have an interactive christmas tree, kinda like a greeting card. This is just meant for me to practice Phaser.

 

Problem:

I've been having issues with a group containing sprites, that are supposed to represent the ornaments of the tree, and detecting an overlap (detect) with a .png sprite containing alpha information to kill off the ornaments if it touches the area -- I'm using Arcade Physics.

The general logic is that if I can get the ornamental objects to be killed off from the interaction of the sprite (aka mask-like object) , I can have randomly generated sprites every refresh, apparently existing inside of the tree.

 

The funny thing is that the overlap() works if I use a 'mask-like' sprite that is the shape of the tree to kill off the ornaments, except that I want it the other way around -- I want the ornaments to exist within the area of the tree and be killed off outside of it. When I do go about it, the other way around, I use a mask-like sprite taking up the whole canvas except a hole where the tree is, yet the whole group disappears.

 

It seems like it has to do with the bounding boxes of my mask-like objects. For the first case, The bounding box is smaller, in the second the bounding box is larger. What I'm looking for is a pixel-perfect solution.

 

I used bitmapData() and its masking method but that didn't work either. Does this have to do with the physics engine in how it calculates bounding boxes?

If there's a workaround that would be of great help. Thanks. I hope this was clear.

Link to comment
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...
 Share

  • Recently Browsing   0 members

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