Can't figure out how to use URLs correctly

I’m trying to animate a sprite’s transparency (tint.w) after a collision, but I don’t know how I would get the correct url of the sprite.

function init(self)
	coinModule = require "main.coinModule"
	self.trigger = hash("trigger_response")
	self.duration = 0.3
	self.pos = hash("position")
end


function on_message(self, message_id, message, sender)
	if message_id == self.trigger then
		if message.enter then
			-- Animation
			go.animate(message.other_id, self.pos, go.PLAYBACK_ONCE_FORWARD, go.get("/plr", hash("position")), go.EASING_OUTQUART, self.duration)
			go.animate(message.other_id#sprite --[[ <----- My problem is here --]], "tint.w", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_LINEAR, self.duration)
			coinModule.changePoints(10)

			-- Delete the collectable
			timer.delay(self.duration-0.1, false, function()
				go.delete(message.other_id, true)
			end)
		end
	end
end

image

There might be a slightly faster way to do this, but generally when I try to get a component I do this:

local spr = msg.url(go.get_id("gameobject"))
spr.fragment = "sprite"

I don’t have a project with collisions open so I’m not sure what will work, but this might work:

local spr = msg.url(message.other_id)
spr.fragment = "sprite"
2 Likes

I am getting this error:
image

I think your go animate needs spr instead of just spr.fragment, because spr is full url to the sprite.

3 Likes

Thanks, that fixed it !

1 Like