TextureButton and CollisionShape2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RetroDan007
:warning: Old Version Published before Godot 3 was released.

Hello everyone.
I have this scene:
In in which I have a TextureButton, and upload an image of 200 x 200.
It is a star who just want to work within the entrella.
Using a CollishionShape2D.
And change to another scene: res //: Scenes / NameScene.tscn

extends Panel
# member variables here, example:

func _ready():
	get_node("TextureButton").connect("pressed",self,"Change_Scene")
	pass

func Change_Scene():
	# CollisionShape Detection 
	get_tree().change_scene("res://Scenes/Escene_01.tscn")
	pass

So what is the problem?

rustyStriker | 2016-09-26 15:56

I donot how to implement the collision in the TextuteButton .
My image is 200 x 200 px. And I just want to work on the star not the entire image

RetroDan007 | 2016-09-26 17:34

:bust_in_silhouette: Reply From: YeOldeDM

A collision shape is not going to give you the behavior you’re looking for here.

You can, however, set the Click Mask of the TextureButton.

To make a click mask:
Create a texture that is identical to your button’s texture.
Any pixel you want to be ‘clickable’ should be white, while all other pixels are black.
Save this mask image in .pbm format.
Load that .pbm file as your Click Mask on the TextureButton

I have had problems using this, untill people on the irc told me to replace the black with alpha (on the png before importing). It worked from then on.

So just to recap, I used alpha for black values, and white wher I wanted the texture to be clickable.

Sojan | 2016-10-07 22:05

:bust_in_silhouette: Reply From: ericdl

Did you set the TextureButton’s click mask?

  • Create a black star with transparent background, save as PNG:
    enter image description here

  • Import the star as a bit mask:
    enter image description here

  • A: Select to the black star file.
    B: Set the target path to save the bit mask into.
    C: Click Import. Godot will create a .PBM file of the star in the target path.
    enter image description here

  • Assign the newly created .PBM file to the TextureButton’s Click Mask property:
    enter image description here

Thanks you men. :slight_smile:

RetroDan007 | 2016-09-27 00:22