CodeBlanks Logo Icon CodeBlanks

What is a Sprite?

Learn how Sprites are used in 2D games.

What is a Sprite?

A Sprite is a two-dimensional graphic asset used in 2D games for characters, props, terrain, and UI elements. Unlike 3D models, sprites contain no depth polygons; they are rendered directly on a 2D coordinate plane.

// Referencing a sprite asset in 2D projects
Sprite heroSprite = Resources.Load<Sprite>("Sprites/Hero");

The game engine optimizes imported digital drawings to render them efficiently in the scene.

Difference between Texture and Sprite

When an image file (PNG or JPG) is added to a project, it is initially recognized as a raw Texture2D. To use this image in a 2D scene, its Texture Type in the Inspector must be set to Sprite (2D and UI).

// Setting Texture Type to Sprite allows binding the image to 2D objects
Texture2D rawImage;
Sprite gameSprite;

This prepares the graphic for 2D capabilities like physics bounds and slicing.

Practice Print Sprite asset type

Assign "Sprite" to assetType and "PNG" to format. Print Asset: Sprite | Format: PNG to the console.

Starter code

Player.cs
using System;

class Program
{
    static void Main()
    {
        // assetType ve format değerlerini tanımlayıp yazdır
    }
}

Sample solution

Player.cs
using System;

class Program
{
    static void Main()
    {
        string assetType = "Sprite";
        string format = "PNG";
        Console.WriteLine("Asset: " + assetType + " | Format: " + format);
    }
}

Expected output

Asset: Sprite | Format: PNG

Questions and answers

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

1 What is a two-dimensional visual asset rendered on screen in 2D games called?

  • Sprite Correct answer
  • AudioMixer
  • ShaderGraph
  • MeshCollider

Explanation: Sprite is the fundamental graphic type representing two-dimensional visual pieces in 2D game development.

2 Load asset of Sprite type

Question
Sprite icon = Resources.Load<____>("Sprites/Coin");
Answer
Sprite icon = Resources.Load<Sprite>("Sprites/Coin");

Explanation: The Sprite generic type is used in Resources.Load to load a two-dimensional graphic asset.

3 2D graphic concepts

Term Meaning
Sprite 2D visual asset rendered in scene
Texture Source texture holding raw pixels
Texture Type Setting for imported file's purpose
2D Space 2D coordinate plane with X and Y axes

All lessons in Beginner