Activating component after some time

I want that my sprite would be activated after 4 seconds but not in time when it called in code?

You would need to send the disable message to the sprite on the init of its parent Game Object. Then send the enable message to it when you want it to be active again.

msg.post("#sprite", "disable")
msg.post("#sprite", "enable")

Maybe exist some function that i missed that can stop compiling code for some time, for example for 4 seconds and after that it will continue compiling?

You can enable and disable sprites and other components by posting a message to the components.

You can achieve a delayed function call in many ways:

  1. Use a timer module of some kind. One example is presented in this post: My sleep() function freezes whole game, ideas? (SOLVED)

  2. Use go.animate on a dummy property:

    go.property(“timer”, 0)
    go.animate("#", “timer”, go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_LINEAR, 4, 0, function()
    msg.post("#sprite", “enable”)
    end)

1 Like

Hi! I noticed disabled game objects still get and process all messages… it was a bit unexpected to me. Is it a correct behavior?

They have to be able to process messages to get the message to activate again. I’ve not experimented with this yet so I can’t comment with certainty about what you should do about it. Maybe in your on_message have it collect messages into a holder if it’s disabled, else pass the messages onto a secondary process_message function with whatever you would want done with your messages sent to that object. Would be worth testing and seeing what is possible… could you explain more of what you observed?

The problem is that there is no such thing as a disabled game object, enable/disable is currently only supported for a limited number of components.

1 Like