I’ve been following the Modify atlas tutorial after searching through forum threads, but I am having no luck.
I keep failing the assert check with the error message “Failed to load resource: /!!Assets/Tiles/BattleTilesTwo.png (-3)”, Now this is a direct resource path copy like the tutorial so I have no idea why it cannot find it.
It could have something to do with finding the compiled asset but I’ve been looking though the build file and my !!Assets file is empty.
I’ve attached the code encase it I mistyped something. Please Help
local function create_buffer_from_image(filename)
local png = assert(sys.load_resource(filename)) --This is the line giving an
--Error message
end
--Newtexture == "/!!Assets/Tiles/BattleTilesTwo.png"
function StageAPI.SwapStageTexture(NewTexture)
local PixelBuffer = create_buffer_from_image(NewTexture)
end
Is this path added to the Custom Resources field of game.project?
“In order for the engine to include custom resources in the build process, you need to specify them in the “custom_resources” key in your “game.project” settings file”
I have done this now, and I seems to be running the whole code now, up until the last line, the actual setting of the texture. I’m now getting a crashdump error with no real feedback on what is going wrong. It’s all just errors from the SRC and Engine files
The only clue I have is a assertation fail, not in the buffer function (see above) but in file ..\src\ddf\ddf.cpp, line 163
which I found in the return print of the create_buffer_from_image function
My inputs are "/!!Features/Tiles/BattleTiles/BattleTileSource.t.texturesetc" for the tilesource "/!!Assets/Tiles/BattleTilesTwo.png" for the png (Now in the custom resource)
I suspect It has something to do with how I implemented the png, as I am using the same create_buffer_function from the example I have linked.
Figured it out, heres the full code for swapping a tilesource at runtime (assuming both png’s are acting as static spritesheets)
local function create_buffer_from_image(filename)
local png = assert(sys.load_resource(filename))
local loaded_image = image.load(png)
local width = loaded_image.width
local height = loaded_image.height
local pixels = loaded_image.buffer
local buffer_declaration = {
{
name = hash("rgba"),
type = buffer.VALUE_TYPE_UINT8,
count = 4
}
}
local pixel_buffer = buffer.create(width * height, buffer_declaration)
local pixel_stream = buffer.get_stream(pixel_buffer, hash("rgba"))
for y = 1, height do
for x = 1, width do
-- flip image vertically
local pixels_index = ((height - y) * width * 4) + ((x - 1) * 4) + 1
local r = pixels:byte(pixels_index + 0)
local g = pixels:byte(pixels_index + 1)
local b = pixels:byte(pixels_index + 2)
local a = pixels:byte(pixels_index + 3)
local stream_index = ((y - 1) * width * 4) + ((x - 1) * 4) + 1
pixel_stream[stream_index + 0] = r
pixel_stream[stream_index + 1] = g
pixel_stream[stream_index + 2] = b
pixel_stream[stream_index + 3] = a
end
end
return pixel_buffer, width, height
end
--My StageAPI object, could just be a local function
function StageAPI.ChangeStage()
--Put in custom resources
local textureset = resource.get_atlas("/!!Features/Tiles/BattleTiles/BattleTileSource.t.texturesetc")
--Tilesources are considered atlas's (I'm not sure if this is mentioned anywhere)
local texture = resource.get_texture_info(textureset.texture)
local pixel_buffer, width, height = create_buffer_from_image("/!!Assets/Tiles/BattleTiles.png")
-- certain position and with a certain size
local first_uvs = textureset.geometries[1].uvs
local x = first_uvs[1] - 48 --Tilesize * 3
local y = first_uvs[2] + 64 --Tilesize * 4
local texture_info = {
type = resource.TEXTURE_TYPE_2D,
width = width,
height = height,
x = x,
y = y,
format = resource.TEXTURE_FORMAT_RGBA,
compression_type = resource.COMPRESSION_TYPE_DEFAULT,
num_mip_maps = texture.mipmaps,
}
resource.set_texture(textureset.texture, texture_info, pixel_buffer)
end