I am following the Runner tutorial. Now, I reached the end of it and trying to add the an effect when the frog collects the coins. I created a particle called coin.particlefx and put it inside the folder particles already but I am sure how to play it from the script file. This is my coin.script:
-- coin.script
function init(self)
self.collected = false
end
function on_message(self, message_id, message, sender)
if self.collected == false and message_id == hash("collision_response") then
self.collected = true
particlefx.play("/particles/coin#emitter")
msg.post("#sprite", "disable")
elseif message_id == hash("start_animation") then
pos = go.get_position()
go.animate(go.get_id(), "position.y", go.PLAYBACK_LOOP_PINGPONG, pos.y + 24, go.EASING_INOUTSINE, 0.75, message.delay)
end
end
Here’s the screenshot of the particle and the error message
This is irrelevant. Where you put the file among your assets has nothing to do with how you play it. Have you attached the coin.particlefx component to a game object? Once you have it attached to a game object you play it like you did above:
Finally, I have managed to make it work. I added the particlefx to the coin game object coin.go and gave it ID of coin_fx and from the coin.script I called like this:
particlefx.play("#coin_fx")
and it works. However, when I used the following syntax, it did not work:
Well, you spawn your coins using a factory right? That means that the generated coins will have varying ids along the line of “instance0”, “instance1” etc. You can use the other_id from the collision message to create a valid URL. (But since you mentioned that you solved it I assume you know this already)