texture.filename

Type String
Object TextureResource
Library graphics.*
Revision Current Public Release (2017.3068)
See also texture.baseDir
texture.type
TextureResource

Overview

Use this property instead of the real file name to create display objects, fills, and use in other places where a real image file name is expected. In these instances, you must also pass texture.baseDir as a parameter — see the examples below for reference.

Gotchas

This texture-related property should not be used to reference the same file in non-texture-related methods — for example, if you specify "background.png" as the filename for the texture when calling graphics.newTexture(), do not attempt to use texture.filename as a reference to the same file in system.pathForFile(). Essentially, this property refers to internal memory, not the file system.

Examples

Image
-- Standard image
local image1 = display.newImageRect( "background.png", 100, 100 )
image1.x = 100
image1.y = 100

-- TextureResource-based image
local texture = graphics.newTexture( { type="image", filename="background.png" } )
local image2 = display.newImageRect(
    texture.filename,  -- "filename" property required
    texture.baseDir,   -- "baseDir" property required
    100,
    100
)
image2.x = 200
image2.y = 100
Image Fill
-- Standard fill
local circle1 = display.newCircle( 100, 100, 50 )
circle1.fill = {
    type = "image",
    filename = "background.png"
}

-- TextureResource-based fill
local texture = graphics.newTexture( { type="image", filename="background.png" } )
local circle2 = display.newCircle( 200, 100, 50 )
circle2.fill = {
    type = "image",
    filename = texture.filename,  -- "filename" property required
    baseDir = texture.baseDir     -- "baseDir" property required
}