← Pixel Dreamer Studio

Pick the growth image so the ripe one shows exactly when the crop can be picked

Use the same test for the ripe image as for harvesting, and share the growing time between the other images.

A farm crop usually picks its image from how far it has grown. With 4 images (seed, sprout, young, ripe) over 60 seconds, int(progress * 4) showed the ripe image 15 s before the crop could be harvested in our Godot 4.7 test, and roundi(progress * 3) 10 s before. int(progress * 3) was on time, but its index ran past the last image 20 s after the crop was ready, because growing kept counting while it waited. Show ripe only when the crop can be harvested: 0 s early, never past the last image.

The code

Set the crop's texture to images[crop_stage(grown, grow_time, images.size())], and let the player harvest when grown >= grow_time, the same test the script uses for the ripe image.

extends Node
## Which growth image a crop shows. The ripe image shows only when the crop can
## really be harvested, and every growing image gets the same share of the time.


static func crop_stage(grown: float, grow_time: float, stages: int) -> int:
	if grown >= grow_time:  # the same test as "can harvest"
		return stages - 1
	var growing := stages - 1  # images before ripe
	return mini(int(grown / grow_time * growing), growing - 1)

What we measured

One crop with 60 s to grow and 4 images at 60 fps, left in the ground until 120 s. Harvest became possible at 60.02 s, one frame late, because 3,600 summed frame times land just under 60. Two runs with the same numbers.

Index 4 is one past the last of 4 images, an out of bounds index on an Array of 4 textures.

Why it happens

The ripe image and the harvest check use different numbers. A formula that rounds up, or multiplies by the full number of images, reaches the last image before progress gets to 1. And progress keeps going past 1 while the crop waits to be picked, so even a formula that is right at 1 runs off the end later.

What to change

Why a summed timer lands a frame late: a timer that never fires on time. The harvest pop itself: pop an item out in an arc.

Ready-made harvest effects: Farming & Harvest VFX for Godot 4 has 23 ready-made farm effects in Stylized and Retro PSX looks, including harvest bursts for carrots, berries and wheat, a Ready to Harvest sparkle and a Giant Crop reward.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Farming & Harvest VFX for Godot 4 has 23 ready-made farm effects in Stylized and Retro PSX looks, including harvest bursts for carrots, berries and wheat, a Ready to Harvest sparkle and a Giant Crop reward.

More how-tos for Farming & Harvest VFX for Godot 4: Make a harvested crop pop out in an arc

More how-tos: Game systems