Tiny Shelf 45 · Frame gameplay for a store preview

Tiny Shelf Studio · Lesson 45 of 50 · Publishing · About 36 min

A useful screenshot shows which products belong together. In a store preview, a squat box of Jam Toast should still look squat.

Tiny fictional paper cartons, jars and tins displayed on a handmade wooden shelf.
What you’ll make Capture the running game and compare how a landscape screenshot fits in differently shaped frames.

Download the projects from the course page. In Godot’s Project Manager, choose Import, select project.godot, and use Run Project (F5). Start from checkpoints/44 when the lesson builds on prior work, or copy the checkpoints/45 folder to try this lesson on its own. Read the file names in the steps before editing.

Plan. Select three moments. → Capture. Use the running build. → Fit. Keep one scale factor. → Verify. Check slot and caption.
Plan → Capture → Fit → Verify
Godot checkpoint window for Frame gameplay for a store preview
From the running Godot checkpoint.

Build it step by step

Language and tools in this lesson Vector2i, float(), minf(), roundi(), aspect ratio, screenshot captions.

  1. Choose the story

    Play a full brief and choose three moments. Read the rules, show a partial display and capture the completed shelf with the brief's stamp. Check the stock and shelf are both visible in at least one image.

    Why it works A sequence of real moments gives the viewer an idea of what they will do.

  2. Capture the running build

    Capture the game with your approved device or Godot's game view for a course example. Close private notifications. Keep originals dated and named with the tested build.

    Why it works An unedited copy keeps the action available to check later.

  3. Compare two frames

    Import checkpoint 45, open main.gd and press F5. Try both buttons. Note how two display shapes take the same 1280 × 720 source.

    Why it works Source and frame proportions can differ. Fit uses one scale in both directions.

  4. Trace the math

    Inspect fit(). Width and height each offer a scaling ratio. Use the smaller so the whole image fits. Predict what happens when the frame's width gets narrower.

    var scale := minf(width_scale, height_scale)

    Why it works The larger value would push part of the source outside its frame.

  5. Verify the actual store slot

    Read the current screenshot requirements for your game's supported devices and orientation. For each planned store upload, check the final file size and proportions. Recapture or make a faithful crop when needed.

    Why it works A classroom fit does not qualify a gameplay image for every store slot.

  6. Write useful captions

    For the course page or portfolio, describe the action visible in each image. For example, Moon Milk and Lemon Fizz share the top shelf while Jam Toast sits beneath Lemon Fizz. Review the text against the actual screenshot.

    Why it works A meaningful caption helps readers understand what is happening without relying on the image alone.

Watch the values change

  1. Fit into a landscape frame The source and frame share the same ratio.
    What you see. The result fills the frame.
  2. Fit into a portrait frame Its width is the tighter limit.
    What you see. The game keeps its shape with unused vertical space.
  3. Prepare the upload Check store device class and size requirements.
    What you see. Choose a correctly captured final file.

Predict before you run Would making the lemonade carton taller without making it wider keep the original proportions?

Reveal the answer

One scale for both dimensions keeps the shape. Use a crop or another capture when the slot has a different shape.

Complete checkpoint

The wide frame fills at 1600 × 900. The portrait frame fits a 900 × 506 image with 1094 pixels of unused height.

main.gd

extends Control

const Lab = preload("res://release_lab.gd")
const PackArt = preload("res://pack_preview.gd")
const TITLE := "Frame gameplay for a store preview"
const NUMBER := 45
var ui: VBoxContainer

func _ready() -> void:
	var preview := Control.new()
	preview.set_script(PackArt)
	preview.mouse_filter = Control.MOUSE_FILTER_IGNORE
	add_child(preview)
	preview.set_anchors_and_offsets_preset(Control.PRESET_RIGHT_WIDE)
	preview.offset_left = -258.0
	preview.offset_right = -28.0
	preview.offset_top = 32.0
	preview.offset_bottom = -32.0
	ui = VBoxContainer.new()
	ui.set_script(Lab)
	add_child(ui)
	ui.start(TITLE, NUMBER)
	build()

const SOURCE := Vector2i(1280, 720)

func build() -> void:
	ui.say("Compare two example frames using a landscape source.")
	ui.option("Fit to 1600 by 900", fit.bind(Vector2i(1600, 900)))
	ui.option("Fit to 900 by 1600", fit.bind(Vector2i(900, 1600)))

func fit(frame: Vector2i) -> void:
	if frame.x < 1 or frame.y < 1:
		ui.say("Choose a positive width and height.")
		return
	var width_scale := float(frame.x) / SOURCE.x
	var height_scale := float(frame.y) / SOURCE.y
	var scale := minf(width_scale, height_scale)
	var result := Vector2i(roundi(SOURCE.x * scale), roundi(SOURCE.y * scale))
	var spare := frame - result
	ui.say("Game image: %d × %d. Unused space: %d across and %d high." % [result.x, result.y, spare.x, spare.y])

release_lab.gd

extends VBoxContainer

var output: Label

func start(title_text: String, lesson_number: int) -> void:
	set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
	offset_left = 35.0
	offset_top = 29.0
	offset_right = -315.0
	offset_bottom = -24.0
	add_theme_constant_override("separation", 12)

	var paper := ColorRect.new()
	paper.color = Color("#142536")
	paper.mouse_filter = Control.MOUSE_FILTER_IGNORE
	get_parent().add_child(paper)
	paper.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
	get_parent().move_child(paper, 0)

	var eyebrow := Label.new()
	eyebrow.text = "TINY SHELF STUDIO   /   LESSON %d" % lesson_number
	eyebrow.add_theme_font_size_override("font_size", 14)
	eyebrow.add_theme_color_override("font_color", Color("#9ce3cf"))
	add_child(eyebrow)

	var title := Label.new()
	title.text = title_text
	title.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
	title.add_theme_font_size_override("font_size", 29)
	title.add_theme_color_override("font_color", Color("#ffe3ae"))
	add_child(title)

	output = Label.new()
	output.custom_minimum_size.y = 132.0
	output.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
	output.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
	output.add_theme_font_size_override("font_size", 20)
	output.add_theme_color_override("font_color", Color("#ecf3f7"))
	add_child(output)

func say(message: String) -> void:
	output.text = message

func option(label: String, command: Callable) -> void:
	var button := Button.new()
	button.text = label
	button.focus_mode = Control.FOCUS_ALL
	button.custom_minimum_size.y = 48.0
	button.add_theme_font_size_override("font_size", 18)
	button.pressed.connect(command)
	add_child(button)

pack_preview.gd

extends Control

func _draw() -> void:
	var cream := Color("#fff1d7")
	var turquoise := Color("#65c9b6")
	var font := ThemeDB.fallback_font
	draw_rect(Rect2(Vector2.ZERO, size), Color("#203951"))
	draw_string(font, Vector2(20, 40), "THE PROTOTYPE SHELF", HORIZONTAL_ALIGNMENT_LEFT, -1, 15, cream)
	draw_rect(Rect2(20, 60, 190, 3), turquoise)
	front(Rect2(42, 124, 111, 143), Vector2(18, -12), Color("#ec9e69"), "LEMON", "FIZZ")
	front(Rect2(100, 288, 86, 101), Vector2(15, -11), Color("#93afd9"), "MOON", "MILK")
	draw_rect(Rect2(18, 396, 194, 7), Color("#5a7b8b"))
	draw_string(font, Vector2(20, 437), "Invented packs · original art", HORIZONTAL_ALIGNMENT_LEFT, -1, 14, cream)

func front(rect: Rect2, depth: Vector2, ink: Color, name_top: String, name_bottom: String) -> void:
	var top_left := rect.position
	var top_right := Vector2(rect.end.x, rect.position.y)
	var side_bottom := rect.end + depth
	draw_colored_polygon(PackedVector2Array([top_left, top_left + depth, top_right + depth, top_right]), ink.lightened(0.28))
	draw_colored_polygon(PackedVector2Array([top_right, top_right + depth, side_bottom, rect.end]), ink.darkened(0.28))
	draw_rect(rect, ink)
	draw_circle(rect.position + rect.size * Vector2(0.72, 0.27), 10, Color("#fff1d7"))
	var font := ThemeDB.fallback_font
	var label_color := Color("#162b3e")
	draw_string(font, rect.position + Vector2(10, 57), name_top, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, label_color)
	draw_string(font, rect.position + Vector2(10, 76), name_bottom, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, label_color)

GDScript line by line

Follow the line numbers, including the indent at the start of each line. Find the code the game will run first, then look for the function that reacts when you tap or change something.

Read main.gd line by line
  1. extends ControlStarts with Godot's Control type. This script gets the abilities of that type and adds the game's own rules.
  2. const Lab = preload("res://release_lab.gd")Load the practice panel's script before the game runs so the scene can give a VBoxContainer those useful methods.
  3. const PackArt = preload("res://pack_preview.gd")Load the drawing script for the original product forms. It has no effect on the checklist logic.
  4. const TITLE := "Frame gameplay for a store preview"Creates a constant named TITLE. The expression uses the text inside the quotes. Godot infers the type from the first value.
  5. const NUMBER := 45Creates a constant named NUMBER. The expression uses the whole number 45. Godot infers the type from the first value.
  6. var ui: VBoxContainerDeclares ui for later use. A colon followed by a type says which kind of value belongs here.
  7. func _ready() -> void:Godot calls this once after the scene and its children are ready. Use it to set up the room and connect controls.
  8. var preview := Control.new()Creates a variable named preview. The expression creates a new Control object. Godot infers the type from the first value.
  9. preview.set_script(PackArt)Attach the illustration behaviour to the new Control. The package drawing now belongs to this node.
  10. preview.mouse_filter = Control.MOUSE_FILTER_IGNOREThe illustration is decorative, so mouse input passes by it instead of stopping there.
  11. add_child(preview)Adds the new node to the scene tree so that Godot can run and draw it.
  12. preview.set_anchors_and_offsets_preset(Control.PRESET_RIGHT_WIDE)Anchor the illustration on the right and stretch its region vertically.
  13. preview.offset_left = -258.0Give the right-side artwork a left edge 258 pixels from its anchored edge.
  14. preview.offset_right = -28.0Give the right edge a 28-pixel margin.
  15. preview.offset_top = 32.0Stores the new value in preview.offset_top. The expression reads 32.0.
  16. preview.offset_bottom = -32.0Stores the new value in preview.offset_bottom. The expression reads -32.0.
  17. ui = VBoxContainer.new()Create a visual container that arranges its children in a column.
  18. ui.set_script(Lab)Calls ui.set_script with the values in its parentheses.
  19. add_child(ui)Adds the new node to the scene tree so that Godot can run and draw it.
  20. ui.start(TITLE, NUMBER)Set up the labelled teaching panel. The next instruction adds this lesson's buttons.
  21. build()The scene is in place. Now add this lesson's practice actions and initial prompt.
  22. const SOURCE := Vector2i(1280, 720)Describe the reference project's logical landscape source as 1280 pixels wide by 720 high.
  23. func build() -> void:Defines build, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  24. ui.say("Compare two example frames using a landscape source.")Calls ui.say with the values in its parentheses.
  25. ui.option("Fit to 1600 by 900", fit.bind(Vector2i(1600, 900)))Calls ui.option with the values in its parentheses.
  26. ui.option("Fit to 900 by 1600", fit.bind(Vector2i(900, 1600)))Calls ui.option with the values in its parentheses.
  27. func fit(frame: Vector2i) -> void:Defines fit, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  28. if frame.x < 1 or frame.y < 1:Reject a box with zero or negative dimensions before calculating a fit.
  29. ui.say("Choose a positive width and height.")Calls ui.say with the values in its parentheses.
  30. returnFinishes the function right here. Any later instructions in this function are skipped.
  31. var width_scale := float(frame.x) / SOURCE.xConvert the width to a float so the quotient can express a fraction or decimal scale.
  32. var height_scale := float(frame.y) / SOURCE.yCalculate the equivalent maximum scale allowed by the frame height.
  33. var scale := minf(width_scale, height_scale)Choose the tighter of the width and height limits to preserve both dimensions without clipping.
  34. var result := Vector2i(roundi(SOURCE.x * scale), roundi(SOURCE.y * scale))Use the same scale on both axes, then round to whole display pixels.
  35. var spare := frame - resultSubtract each image dimension from its frame dimension to measure unused space.
  36. ui.say("Game image: %d × %d. Unused space: %d across and %d high." % [result.x, result.y, spare.x, spare.y])Calls ui.say with the values in its parentheses.
Read release_lab.gd line by line
  1. extends VBoxContainerStarts with Godot's VBoxContainer type. This script gets the abilities of that type and adds the game's own rules.
  2. var output: LabelDeclares output for later use. A colon followed by a type says which kind of value belongs here.
  3. func start(title_text: String, lesson_number: int) -> void:Defines start, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  4. set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Start with a panel attached to all four edges of its parent.
  5. offset_left = 35.0Stores the new value in offset_left. The expression reads 35.0.
  6. offset_top = 29.0Stores the new value in offset_top. The expression reads 29.0.
  7. offset_right = -315.0Leave 315 pixels of space for artwork beside the exercises.
  8. offset_bottom = -24.0Stores the new value in offset_bottom. The expression reads -24.0.
  9. add_theme_constant_override("separation", 12)Calls add_theme_constant_override with the values in its parentheses.
  10. var paper := ColorRect.new()Creates a variable named paper. The expression creates a new ColorRect object. Godot infers the type from the first value.
  11. paper.color = Color("#142536")Stores the new value in paper.color. The expression builds a colour from these values.
  12. paper.mouse_filter = Control.MOUSE_FILTER_IGNORELet clicks pass through the background so it cannot interrupt a button.
  13. get_parent().add_child(paper)Calls get_parent with the values in its parentheses.
  14. paper.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)Stretch the paper colour to the full scene edge.
  15. get_parent().move_child(paper, 0)Place the paper first in drawing order, behind the artwork and teaching panel.
  16. var eyebrow := Label.new()Creates a variable named eyebrow. The expression creates a new Label object. Godot infers the type from the first value.
  17. eyebrow.text = "TINY SHELF STUDIO / LESSON %d" % lesson_numberThe integer in lesson_number replaces %d in the heading string.
  18. eyebrow.add_theme_font_size_override("font_size", 14)Calls eyebrow.add_theme_font_size_override with the values in its parentheses.
  19. eyebrow.add_theme_color_override("font_color", Color("#9ce3cf"))Calls eyebrow.add_theme_color_override with the values in its parentheses.
  20. add_child(eyebrow)Adds the new node to the scene tree so that Godot can run and draw it.
  21. var title := Label.new()Creates a variable named title. The expression creates a new Label object. Godot infers the type from the first value.
  22. title.text = title_textUpdates title.text, which controls the words a player sees. The expression reads title_text.
  23. title.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTAllow a long heading to wrap on word boundaries.
  24. title.add_theme_font_size_override("font_size", 29)Calls title.add_theme_font_size_override with the values in its parentheses.
  25. title.add_theme_color_override("font_color", Color("#ffe3ae"))Calls title.add_theme_color_override with the values in its parentheses.
  26. add_child(title)Adds the new node to the scene tree so that Godot can run and draw it.
  27. output = Label.new()Stores the new value in output. The expression creates a new Label object.
  28. output.custom_minimum_size.y = 132.0Keep a stable 132-pixel space for the result, so the buttons stay in place when the text changes.
  29. output.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTFit multi-line results to the current width without requiring horizontal scrolling.
  30. output.vertical_alignment = VERTICAL_ALIGNMENT_CENTERStores the new value in output.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_CENTER.
  31. output.add_theme_font_size_override("font_size", 20)Calls output.add_theme_font_size_override with the values in its parentheses.
  32. output.add_theme_color_override("font_color", Color("#ecf3f7"))Calls output.add_theme_color_override with the values in its parentheses.
  33. add_child(output)Adds the new node to the scene tree so that Godot can run and draw it.
  34. func say(message: String) -> void:Defines say, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  35. output.text = messageReplace the practice status with a result the player can read.
  36. func option(label: String, command: Callable) -> void:Defines option, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  37. var button := Button.new()Creates a variable named button. The expression creates a new Button object. Godot infers the type from the first value.
  38. button.text = labelUpdates button.text, which controls the words a player sees. The expression reads label.
  39. button.focus_mode = Control.FOCUS_ALLKeep the button reachable by keyboard as well as a pointer or touch.
  40. button.custom_minimum_size.y = 48.0Give the control a taller hit area.
  41. button.add_theme_font_size_override("font_size", 18)Calls button.add_theme_font_size_override with the values in its parentheses.
  42. button.pressed.connect(command)Connect the press signal to the supplied action. That action runs when a learner chooses the button.
  43. add_child(button)Adds the new node to the scene tree so that Godot can run and draw it.
Read pack_preview.gd line by line
  1. extends ControlStarts with Godot's Control type. This script gets the abilities of that type and adds the game's own rules.
  2. func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state.
  3. var cream := Color("#fff1d7")Creates a variable named cream. The expression builds a colour from these values. Godot infers the type from the first value.
  4. var turquoise := Color("#65c9b6")Creates a variable named turquoise. The expression builds a colour from these values. Godot infers the type from the first value.
  5. var font := ThemeDB.fallback_fontUse an engine-supplied font so the drawings and text need no extra download.
  6. draw_rect(Rect2(Vector2.ZERO, size), Color("#203951"))Fill the local area from the upper left to the current width and height.
  7. draw_string(font, Vector2(20, 40), "THE PROTOTYPE SHELF", HORIZONTAL_ALIGNMENT_LEFT, -1, 15, cream)Paints a piece of text with a font at a position measured from the node's origin.
  8. draw_rect(Rect2(20, 60, 190, 3), turquoise)Paints a rectangle at the given position and size.
  9. front(Rect2(42, 124, 111, 143), Vector2(18, -12), Color("#ec9e69"), "LEMON", "FIZZ")Draw the Lemon Fizz face with its width, height, invented name, ink and depth.
  10. front(Rect2(100, 288, 86, 101), Vector2(15, -11), Color("#93afd9"), "MOON", "MILK")Draw a smaller, bluer Moon Milk pack. The depth vector gives it a separate top and side.
  11. draw_rect(Rect2(18, 396, 194, 7), Color("#5a7b8b"))Paints a rectangle at the given position and size.
  12. draw_string(font, Vector2(20, 437), "Invented packs · original art", HORIZONTAL_ALIGNMENT_LEFT, -1, 14, cream)Paints a piece of text with a font at a position measured from the node's origin.
  13. func front(rect: Rect2, depth: Vector2, ink: Color, name_top: String, name_bottom: String) -> void:Defines front, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  14. var top_left := rect.positionCreates a variable named top_left. The expression reads rect.position. Godot infers the type from the first value.
  15. var top_right := Vector2(rect.end.x, rect.position.y)Use the right end and the upper y coordinate to find the top-right corner.
  16. var side_bottom := rect.end + depthOffset the bottom-right corner by the depth vector to finish the angled side.
  17. draw_colored_polygon(PackedVector2Array([top_left, top_left + depth, top_right + depth, top_right]), ink.lightened(0.28))Connect the four corners of the top, and lighten its colour as if light fell on it.
  18. draw_colored_polygon(PackedVector2Array([top_right, top_right + depth, side_bottom, rect.end]), ink.darkened(0.28))Connect the four corners of the right side. Darkening the ink makes the three-dimensional edge clearer.
  19. draw_rect(rect, ink)Paints a rectangle at the given position and size.
  20. draw_circle(rect.position + rect.size * Vector2(0.72, 0.27), 10, Color("#fff1d7"))Use a relative point inside the rectangle so the round badge is placed consistently on both packs.
  21. var font := ThemeDB.fallback_fontUse an engine-supplied font so the drawings and text need no extra download.
  22. var label_color := Color("#162b3e")Creates a variable named label_color. The expression builds a colour from these values. Godot infers the type from the first value.
  23. draw_string(font, rect.position + Vector2(10, 57), name_top, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, label_color)Write the product name on its face, with its own inset inside the shape.
  24. draw_string(font, rect.position + Vector2(10, 76), name_bottom, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, label_color)Write the product name on its face, with its own inset inside the shape.

Find and fix a bug

If the packaging and shelf look stretched, compare the source's ratio to the edited copy and start from the original.

Try a change

Ages 10–12. Choose and caption three screenshots. Ages 13–16. Calculate a fit and decide what a crop would remove.

Official instructions