Getting started - Introduction - Installing Defold - The editor - Glossary - Defold for Flash users - Getting help Project setup - Creating a project - Project settings - Libraries Core concepts - Building blocks - Addressing - Message passing - Application lifecycle Assets and resources - Importing assets - Importing 2D graphics - Importing 3D models - Adapting to different screen sizes - Live update - Animation - Atlas - Font - Resource management - Tile source - Texture filtering - Texture profiles Components - Overview - Collection factory - Collection proxy - Collision object - Camera - Factory - Label - Mesh - Model - Particle FX - Sound - Spine animation - Spine model - Sprite - Tilemap Gui - GUI overview - Box nodes - Text nodes - Pie nodes - Spine nodes - ParticleFX nodes - Template nodes - Scripts - Clipping - Layouts Physics - Physics overview - Collision objects - Collision shapes - Collision groups - Collision messages - Resolving collisions - Ray casts - Joints and constraints Sound - Sound - FMOD Input - Overview - Key and text input - Mouse and touch - Gamepads Game logic - Scripts - Properties - Script properties - Lua in Defold - Modules - Debugging - Writing code Saving and loading files - Working with files Networking - Overview - HTTP Requests - Socket connections - WebSocket connections - Online services Rendering - Render - Material - Shader - Texture filtering Workflow - Adapting to different screen sizes - Bundling an application - Bob the builder - Hot reloading - Optimizing an application - Profiling - Refactoring - The mobile dev app - Version control - Writing code - Working offline Debugging - Debugging game logic - Debugging native code - Debugging native code on Android - Debugging native code on iOS - Reading game and system logs - Profiling Platforms - Android - iOS - Nintendo Switch - Linux - HTML5 - macOS - Windows Monetization - Ads - In-app purchases - Web Monetization Extensions - Advertising Info - Camera - Facebook - Facebook Instant Games - Firebase Analytics - Google Play Game Services - Google Play Instant - In-app purchases - Inter-app communication - Push notifications - App review and ratings - WebMonetization - WebSocket - Webview Native extensions - Introduction - Details - Defold SDK - Adding auto-complete definition - Best Practices - Debugging - Build Variants - Manifest Merging Editor extensions - Editor scripts
Sprites
A Sprite component is a simple image or flipbook animation that is displayed on screen.
The Sprite component can use either an Atlas or a Tile Source for it’s graphics.
Sprite properties
Apart from the properties Id , Position and Rotation the following component specific properties exist:
Image
The atlas or tilesource resource to use for the sprite.
DefaultAnimation
The animation to use for the sprite.
Material
The material to use for rendering the sprite.
Blend Mode
The blend mode to use when rendering the sprite.
Blend modes
The Blend Mode property defines how the component graphics should be blended with the graphics behind it. These are the available blend modes and how they are calculated:
Alpha
Normal blending: src.a * src.rgb + (1 - src.a) * dst.rgb
Add
Brighten the background with the color values of the corresponding pixels of the component: src.rgb + dst.rgb
Multiply
Darken the background with values of the the corresponding pixels of the component: src.rgb * dst.rgb
Runtime manipulation
You can manipulate sprites in runtime through a number of different functions and properties (refer to the API docs for usage ). Functions:
sprite.play_flipbook()
- Play an animation on a sprite component.
sprite.set_hflip()
and sprite.set_vflip()
- Set horizontal and vertical flipping on a sprite’s animation.
A sprite also has a number of different properties that can be manipulated using go.get()
and go.set()
:
cursor
The normalized animation cursor (number
).
image
The sprite image (hash
). You can change this using an atlas or tile source resource property and go.set()
. Refer to the API reference for an example .
material
The sprite material (hash
). You can change this using a material resource property and go.set()
. Refer to the API reference for an example .
playback_rate
The animation playback rate (number
).
scale
The non-uniform scale of the sprite (vector3
).
size
The size of the sprite (vector3
) (READ ONLY).
Material constants
The default sprite material has the following constants that can be changed using go.set() or go.animate() (refer to the Material manual for more details ). Examples:
go . set ( "#sprite" , "tint" , vmath . vector4 ( 1 , 0 , 0 , 1 ))
go . animate ( "#sprite" , "tint" , go . PLAYBACK_LOOP_PINGPONG , vmath . vector4 ( 1 , 0 , 0 , 1 ), go . EASING_LINEAR , 2 )
tint
The color tint of the sprite (vector4
). The vector4 is used to represent the tint with x, y, z, and w corresponding to the red, green, blue and alpha tint.
Project configuration
The game.project file has a few project settings related to sprites.