We will set up a generic fruit (apple) upon which we base all the other fruit types
Grab the graphical assets here =>
Create a new scene with CharacterBody2D as root
Add a Sprite2D as a child
Add apple_small.png as Texture
Add a new Node2D as child of Fruit
Add a CharacterBody2D as child
Add a TextureRect as child
Set the Texture to apple_small.png
It should overlap the existing apple
It should appear as though there
Select the Half1 TextureRect
Resize and reposition it so that
It cuts the apple in half horizontally
Set Clip Children to Clip Only
If you make WholeFruit invisible now
You will see the top half of the apple only
Select Half1 and duplicate it
Reposition it to cut through the
If you hide the Half1 Sprite2D
To create the vertical slices
It must be a child of Fruit
This is for the left and right
Reposition it to the left
Now if you hide the WholeFruit
You will see only the left side
Reposition it to the right
Now if you hide the WholeFruit
You will see only the right side
Create a new Node2D as child of Fruit
Rename it to SlicedRightSlash
Add a CharacterBody2D as child
Add a TextureRect as child
Select the Sprite2D of Half1
Add the apple_small.png Texture
Select the Half1 TextureRect
If you hide the other sections
You can see the slice you have made
Duplicate the Half1 of SlicedRightSlash
Select the Half2 TextureRect
Reposition it to be at the bottom right
If you hide the other sections
You can see the slice you have made
Duplicate the SlicedLeftSlash
Reposition the TextureRects
Ensure your slices are correct
In order to detect the slash directions, we must set up some areas and collisions
Create an Area2D as a child of Fruit
Rename it to HorizontalSlashArea
Add a CollisionShape2D as child
Add a new RectangleShape2D
Extend it through the Apple
Create an Area2D as a child of Fruit
Rename it to VerticalSlashArea
Add a CollisionShape2D as child
Add a new RectangleShape2D
Extend it through the Apple
Create an Area2D as a child of Fruit
Rename it to DiagonalRightSlashArea
Add a CollisionShape2D as child
Add a new RectangleShape2D
Extend it through the Apple
Create an Area2D as a child of Fruit
Rename it to DiagonalLeftSlashArea
Add a CollisionShape2D as child
Add a new RectangleShape2D
Extend it through the Apple
Finally, add a VisibleOnScreenNotifier
Expand the area of the VisibleOnScreenNotifier Node
To cover more than the size of the apple
To accomodate different types of Fruit
Add a New Script to the Fruit Node