steamworks.newImageRect()

Type Function
Return value DisplayObject
Revision Release 2024.3703
Keywords steam, steamworks, newImageRect
See also steamworks.getAchievementImageInfo()
steamworks.getUserImageInfo()
steamworks.newTexture()
steamworks.*

Overview

Displays a Steam image by its unique imageHandle property that was retrieved by the steamworks.getAchievementImageInfo() or steamworks.getUserImageInfo() functions.

This function works like the Corona display.newImageRect() function where you can specify the width and height at which the Steam image will be scaled relative to the content width and height defined in config.lua.

Gotchas

This function will return nil in the following cases:

Syntax

steamworks.newImageRect( [parent,] imageHandle, width, height )
parent (optional)

GroupObject. An optional display group in which to insert the image.

imageHandle (required)

Number. Unique identifier of the Steam image to load and display. This identifier is provided by an ImageInfo object's imageHandle property.

width (required)

Number. The content width at which to scale the Steam image.

height (required)

Number. The content height at which to scale the Steam image.

Example

local steamworks = require( "plugin.steamworks" )

-- Fetch information about the currently logged in user's medium-sized avatar
local imageInfo = steamworks.getUserImageInfo( "mediumAvatar" )
if ( imageInfo == nil ) then
    return
end

-- Display the user's avatar scaled to 64x64 content coordinates on the left
local avatarImage = steamworks.newImageRect( imageInfo.imageHandle, 64, 64 )
if ( avatarImage ) then
    avatarImage.x = display.contentWidth * 0.25
    avatarImage.y = display.contentCenterY
end

-- Display the user's avatar unscaled and "pixel perfect" on the right
local avatarImage = steamworks.newImageRect(
    imageInfo.imageHandle,
    imageInfo.pixelWidth * display.contentScaleX,
    imageInfo.pixelHeight * display.contentScaleY )
if ( avatarImage ) then
    avatarImage.x = display.contentWidth * 0.75
    avatarImage.y = display.contentCenterY
end