How do I change the width of a sprite based on an existing timer?

  • I'm currently making a system where you walk in front of a treasure chest, and if you aren't moving or attacking, you will open it after a few seconds using a Timer behavior.

    I want to make this visible to the player through an "interaction bar" which appears under the player. It should change its width based on how long the timer has been running.

    I've tried using the Timer expressions, but for some reason these are always 0. Am I using them wrong, or is there a different approach?

    Here's my project file: ufile.io/b2vfg

    The logic I've added is in the eCharacters and eInteractions event sheets. I'm trying to change the width of the "castbar" sprite.

  • Bug is with the set width action, you used castbar.timer when treasure has the timer.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Didn't downloaded the file however the bellow is my solution.

    a simple way to achieve this, would be: having 2 instance_variables on the player one that detects if he is_moving, and one that keeps a value amount let's say timeWait=60.

    (make sure to add the keyboard key is not pressed condition/s for each user keystroke that can be inputed)

    (0 false 1 true - if user is pressing a key it means the player is moving then the value changes to 1, if there is no user input then value changes back to 0)

    then you can reset the timewait by saying

    that way it always resets when the user presses a button.

    that should work, is not the most elegant but should give you and idea on how the mechanics should work, and then apply and tweak them based on already used behaviors, or code you have.

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