Jump to content

[Question/Help] Can I use a PNG binary mask for hitover area instead of polygon?


newbiedev
 Share

Recommended Posts

Hello, as the title implies, I'm trying to create a hitover area using a PNG binary mask instead of a polygon mask. I couldn't really find something for this in the documentation. Is that possible?

Currently, I start with a PNG binary mask, convert it to a polygon (list of [x,y] coordinates), and then mask my sprites for a hitover area. This works really well when the initial binary mask is well defined and closed. However, if the binary mask has disconnected components, the hitover area yields unwanted actions. Probably due to there being multiple polygons during the mask -> polygon process.

Thanks so much in advance!

Link to comment
Share on other sites

reshape(3,3,3) #3 channel image mask = np. zeros(shape=(3,3)) mask[1,1] = 1 # binary mask mask_3d = np. stack((mask,mask,mask),axis=0) #3 channel mask ## Answer 1 # Simply multiply the image array with the mask masked_arr = arr*mask_3d ## Answer 2 # Use the where function in numpy masked_arr = np.

Link to comment
Share on other sites

  • 5 months later...

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...