Help tracking down bug -- Setting sprite color "on created" doesn't work

0 favourites
  • 3 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • There's a bug in my code...

    I want to set the color of a sprite when it's created. If I call "setColor" in the "sprite on created" trigger, nothing happens. Even if I add a wait() before the setColor action, the color doesn't change. Doesn't matter what wait time I use.

    I created a test project and saw that calling "setColor" in the "sprite on created" trigger does indeed set the color as expected, so something in my code is messed up. But I can't for the life of me figure out what. The sprite is being created at runtime and is not in the layout at startup. There's no other "set color" call in my code. Any thoughts on what may be causing this?

    Thanks

  • Check that the "On created" trigger is actually triggered. The easiest way is to add a "Browser Log" action, then you can see if the message appears in browser console.

    If you discover that the event is not triggered, check if the event sheet is connected to your layout, or included in your main event sheet, that the event group is activated etc.

    By the way, I believe if the object is very dark or black, the "Set color" action will have no effect.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Spot on. Not sure why I didn't add my standard "printToError" call to see what was up. I had an additional condition after "on created" checking if the sprite's instance variable was set to a specific value, but of course that hasn't yet been set when "on created" is called. I now wait(0) in the "on created", then check the instance variable. Works great.

    Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)