i am trying to get a sprite to load in an image as its texture. these image(s) are not able to be built into the game, as they are loose user-made files.
i’ve managed to set the texture of a sprite, however, the result is not the actual image, but the bottom right 1/4th of the image flipped upside down and at double size to fit the actual size of the image.
here is the code that sets the texture:
function on_message(self, message_id, message, sender)
local _=images[message.img]
local buf =buffer.create(_.width*_.height , {{name=hash("rgba"), type=buffer.VALUE_TYPE_UINT8, count=4 }} )
local bs= buffer.get_stream(buf, hash"rgba")
for i=1,#_.buffer do
bs[i]=_.buffer:sub(i,i):byte() or 0
end
local head={ width=_.width, height=_.height, type=resource.TEXTURE_TYPE_2D, format=resource.TEXTURE_FORMAT_RGBA }
resource.set_texture(go.get("#sprite", "texture0"), head, buf)
end
here is the image i am using:
versus how it actually appers in-game:
i’m not really sure what i’m doing wrong here, and the end result is even more confusing to me. the images being loaded in are in a .png format, which the engine can load in (the image table values are the result of an image.load() on the image file). the sprites are given an initial testing texture that is a 64x64 image (stored in an atlas with other unused image sizes), the same size as the image i am trying to load in.