Class TextureAsset

java.lang.Object
net.risingworld.api.assets.Asset
net.risingworld.api.assets.TextureAsset

public class TextureAsset extends Asset
Represents a texture / image asset.

Important: Images get compressed to DXT format automatically, so it's recommendable to either use a power of two texture size (e.g 256, 512, 1024, 2048 etc), or at least a width/height which is a multiple of 4 - otherwise compression is not possible and the texture will consume 4-8 times more VRAM. Please bear in mind that the file size is not related to the actual memory consumption. But it's still a good idea to keep an eye on the file size to keep the download sizes low in multiplayer.

Supported file formats: jpg, jpeg, png, gif, tga, tiff, bmp
  • Method Details

    • loadFromGame

      public static TextureAsset loadFromGame(String path)
      Loads a texture / image from the game assets. This is quite efficient because the server doesn't have to send any data to the clients.
      Parameters:
      path - the path to the game texture.
      Returns:
      a new texture asset instance.
    • loadFromFile

      public static TextureAsset loadFromFile(String file)
      Creates a new texture asset instance and loads the texture / image from a file on the hard drive.
      Parameters:
      file - the path to the texture file on the harddrive.
      Returns:
      a new texture asset instance.
      Example: Load image "Banner.jpg" from "assets" subfolder in plugin directory
      1TextureAsset tex = TextureAsset.loadFromFile(getPath() + "/assets/Banner.jpg");
      2// do something with the asset
    • loadFromPlugin

      public static TextureAsset loadFromPlugin(Plugin plugin, String resource)
      Creates a new texture asset instance and loads the texture / image from the plugin jar file.
      Parameters:
      plugin - a reference to the plugin. This is required to make sure the game loads the resource from the correct plugin jar.
      resource - the path to the resource (inside the jar file).
      Returns:
      a new texture asset instance.
      Example: Load image "Banner.jpg" from jar file (in package rw.plugin.images)
      1TextureAsset tex = TextureAsset.loadFromFile(this, "/rw/plugin/images/Banner.jpg");
      2// do something with the asset
    • loadFromAssetBundle

      public static TextureAsset loadFromAssetBundle(AssetBundle bundle, String path)
    • loadFromURL

      public static TextureAsset loadFromURL(String url)
      Loads a texture from an URL
      Parameters:
      url - the URL you want to download the image from.
      Returns:
      a new texture asset instance.
      Example: Load image from an URL
      1TextureAsset tex = TextureAsset.loadFromURL("https://images.rising-world.net/media/update/api/plugin_api3.jpg");
      2// do something with the asset
    • load

      public static TextureAsset load(byte[] data)
      Loads a texture from raw byte data.
      Parameters:
      data - the raw byte data representing a PNG/JPG image (or any other supported format).
      Returns:
      a new texture asset instance.