I am working with a new project from the ‘Desktop Game’ template.
I have a main.collection with one game object that has a sprite component pointing to the main.atlas
I created a new atlas with a “player” animation
what i want to do is set the atlas of a game object using the go.property + resource.atlas()during the init(self) lifecycle function.
I put this in a script and attach it to the game object and it works fine.
local init(self)
go.property("my_atlas", resource.atlas("/asset/atlas/player.atlas"))
go.set("#sprite", "image", self.my_atlas)
sprite.play_flipbook("#sprite", "player")
end
when I run it the game object that has the logo sprite configured displays the custom sprite I added in the player.atlas.
now if I do something like this it does not work, but what I am ultimately trying to get working:
local init(self)
local atlas_path = "/asset/atlas/player.atlas"))
go.property("my_atlas", resource.atlas(atlas_path))
go.set("#sprite", "image", self.my_atlas)
sprite.play_flipbook("#sprite", "player")
end
I know from the documentation that resource.atlas() takes a string and returns a hash, but it seems like it doesn’t support passing a string as a variable?
If I run the below code those debug statements print ‘nil’ for the actual value and the type, but printing the type of path shows as a string.
function init(self)
local atlas_path = "/asset/atlas/player.atlas"
print(type(atlas_path))
go.set("#sprite", "size", vmath.vector3(64,128,0))
go.property("my_atlas", resource.atlas(atlas_path))
print("ENTITY DEBUG: self.my_atlas =", self.my_atlas)
print("ENTITY DEBUG: self.my_atlas type =", type(self.my_atlas))
go.set("#sprite", "image", self.my_atlas)
sprite.play_flipbook("#sprite", "player")
msg.post("@render:", "use_fixed_fit_projection", { near = -1, far = 1 })
end
I figured it might be related to this topic:
So I made a second game object and attached a sprite that did reference /asset/atlas/player.atlas directly as a way to try to force the game to load the atlas for further reference but it doesnt work either.
Is there something I am missing or is there a better way to do this? I saw that textures and atlases can be created at runtime but I figured I would run this down before I try that.
