June 2018
Beginner to intermediate
298 pages
7h 38m
English
The Collectible's script needs to do two things:
For the first part, add the following code to the new script:
extends Area2Dsignal pickupvar textures = {'cherry': 'res://assets/sprites/cherry.png', 'gem': 'res://assets/sprites/gem.png'} func init(type, pos): $Sprite.texture = load(textures[type]) position = pos
The pickup signal will be emitted when the player collects the item. In the textures dictionary, you have a list of the item types and their corresponding texture locations. Note that you can quickly paste those file paths by right-clicking on the file in the FileSystem dock and choosing Copy Path:
Next, you have an init() ...
Read now
Unlock full access