#how do this overall
3 messages · Page 1 of 1 (latest)
Hi Christianguy This involves learning about:
- Coding: Variables
How to save and change different pieces of data
Variables belong to objects and nodes just like functions do (they are properties) - Nodes
Building blocks of your game, objects that have built-in functions and variables
Nodes can "belong to" other nodes, which creates the tree-like structure that nodes are arranged in, parent/child relationships
Example: A Sprite2D node with a lego PNG attached to itstexturevariable - Scenes
A way to save a collection of nodes
An easy way to make a copy of a node/collection of nodes and spawn it into the game
Example: A Sprite2D node, with a script "lego.gd" attached, saved as "lego.tscn" which you then
load(),instantiate()andadd_child()to finally add it to the main scene tree
var new_lego = load("res://lego.tscn").instantiate()
get_tree().current_scene.add_child(new_lego)
- Getting the mouse position
get_global_mouse_position() - Tilemaps
An easy way to divide your game up into a grid
It has functions likemap_to_global()andglobal_to_map(), which convert back and forth between global coordinates and the coordinates of the grid/tilemap. This provides an easy way to center an object to a grid position.
Example:
var grid_pos = global_to_map(get_global_mouse_position())
global_position = map_to_global(grid_pos)
- Getting input (detecting mouse click)
Example: Set up a new input action in your project settings (button at top left of your screen), name it left_click, set up the keybind.
Then do:
func _input(event):
if Input.is_action_pressed("left_click"):
# Spawn a new lego scene, and then snap its global position to the grid pos
I'll do this a tomorrow busy