Type Function Return value TextureResourceExternal Revision Release 2024.3703 Keywords steam, steamworks, newTexture See also steamworks.getAchievementImageInfo() steamworks.getUserImageInfo() steamworks.newImageRect() steamworks.*
Loads a Steam image to a texture by its unique imageHandle that was retrieved by the steamworks.getAchievementImageInfo() or steamworks.getUserImageInfo() functions.
The returned texture can be shown by the display.newImage() and display.newImageRect() functions. The texture can also be applied to an existing ShapeObject via its fill property.
This function will return nil
in the following cases:
false
, indicating that the application is not currently connected to the Steam client.steamworks.newTexture( imageHandle )
Number. Unique identifier of the Steam image to load as a texture. This identifier is provided by an ImageInfo object’s imageHandle property.
local steamworks = require( "plugin.steamworks" ) -- Create a rectangle which we'll later fill with the avatar image local defaultAvatarWidth = 184 * display.contentScaleX local defaultAvatarHeight = 184 * display.contentScaleY local avatarImage = display.newRect( display.contentCenterX, display.contentCenterY, defaultAvatarWidth, defaultAvatarHeight ) -- Updates the above display object's "fill" to show the newest large avatar image local function updateAvatar() -- Attempt to fetch info about the user's large avatar image local imageInfo = steamworks.getUserImageInfo( "largeAvatar" ) if ( imageInfo == nil ) then return end -- Load the avatar image into a new texture resource object local newTexture = steamworks.newTexture( imageInfo.imageHandle ) if ( newTexture == nil ) then return end -- Update the display object to show the avatar image avatarImage.fill = { type = "image", filename = newTexture.filename, baseDir = newTexture.baseDir } -- Release the texture reference newTexture:releaseSelf() end -- Attempt to update the display object with Steam's current image, if available -- If not currently available, this function call will trigger Steam to download it -- In this case, it dispatches a "userInfoUpdate" event to be received below updateAvatar() -- Set up a listener to be called when a user's info has changed local function onUserInfoUpdated( event ) -- Update display object only when the current user's avatar changes if ( steamworks.userSteamId == event.userSteamId ) then if ( event.largeAvatarChanged ) then updateAvatar() end end end steamworks.addEventListener( "userInfoUpdate", onUserInfoUpdated )