Default sprite assignment

Why the code doesn’t work. I need to make sure there is a random background when initializing an object.

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("@render:", "use_fixed_fit_projection")
	--math.randomseed(socket.gettime())
	self.bg = math.random()
	if self.bg > 0.5 then
		go.set("bg#sprite", "default_animation", "bg1")
	else
		go.set("bg#sprite", "default_animation", "bg2")
	end
end

Writes that I can access.
help

Editor scripts are completely different from game scripts, they’re for running custom actions in the editor. Those property names are generally not the same as the ones available to your game code.

What you want is sprite.play_flipbook.

Can’t I access component properties other than position, rotation and scale?

This is well documented in the API docs. This is what’s available for game objects and sprites.

1 Like

Check documentation for sprite.play_flipbook() to change default image/animation for a sprite.