CodeBlanks Logo Icon CodeBlanks

Node2D and Sprite2D

Learn the Node2D and Sprite2D nodes.

What is Node2D?

Node2D is the base node used for all two-dimensional objects in 2D game development. It holds transform properties in 2D space such as position (position), rotation (rotation), and scale (scale). It does not render anything visually on its own, but serves as the foundation of the 2D hierarchy.

extends Node2D

func _ready():
    position = Vector2(50, 100)
    print(position)

Rendering visuals with Sprite2D

Sprite2D is a node derived from Node2D used to draw 2D images and textures in a scene. An image file is assigned to its texture property to display it on screen. It inherits all position and scale properties from Node2D in the scene tree.

extends Sprite2D

func _ready():
    print(texture != null)

Practice Print Output with Sprite2D

In the script defined with extends Sprite2D, print the message to the screen by writing print("Sprite2D hazır") inside the _ready() function.

Starter code

Player.cs
extends Sprite2D

func _ready():
    # Ekrana "Sprite2D hazır" yazdır
    pass

Sample solution

Player.cs
extends Sprite2D

func _ready():
    print("Sprite2D hazır")

Expected output

Sprite2D hazır

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What primary feature does Node2D provide over the base Node class?

  • Calculating coordinates exclusively in 3D space
  • Being an abstract class that cannot be added to the scene tree
  • Ability to play audio files directly
  • Having position, rotation, and scale transforms in 2D space Correct answer

Explanation: Node2D adds positioning and transform properties in 2D space.

2 Inherit from Sprite2D

Question
extends ____

func _ready():
    pass
Answer
extends Sprite2D

func _ready():
    pass

Explanation: extends Sprite2D is used for 2D visual objects.

3 2D Node Concepts

Term Meaning
Node2D Base node for 2D position & transform
Sprite2D Node rendering 2D images and textures
position Coordinate vector in 2D space
texture Image resource for Sprite2D

All lessons in Beginner