Creating a sprite

You can create a sprite from script using the UIAddSprite function. The sprite dimension and position are expressed in pixel in the virtual screen coordinate system. There are several functions available to position and transform sprites such as: SpriteSetPosition, SpriteSetRotation or SpriteSetScale.

At any time, you can change the sprite texture using the SpriteSetTexture function.

Here is a (voluntary verbose) example on how to create a fullscreen background:


                          
  1. // Get the 2D scene associated with every 3D scene.
  2. local ui = SceneGetUI(scene_3d)
  3.  
  4. // Set the 2D scene virtual resolution to 720p (1280x720 pixel).
  5. UISetInternalResolution(ui, 1280, 720)
  6.  
  7. // Load the background texture from a PNG file.
  8. local bg_texture = EngineLoadTexture(g_engine, "bg_1280_720.png")
  9.  
  10. // Create a fullscreen sprite with no texture.
  11. local sprite = UIAddSprite(ui, -1, NullTexture, 0, 0, 1280, 720)
  12.  
  13. // Assign the sprite texture.
  14. SpriteSetTexture(sprite, bg_texture)