How do I set a position of a sprite whenever a variable increases?

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hia folks,

    I'm basically trying to have a representation of time passing in a day with 2 sprites. 1 sprite (at the bottom) is a long line, 54px long with a gradient showing the stages of the day (dark blue, dark orange, orange,yellow, light blue, blue, dark blue again). A second sprite is basically a round object that I want to move across the gradient line as the day in the game goes by. I have several variables that count seconds/minutes/hours/days.

    Basically, I want it so that every time the "hours" variable increases by 1, for the second sprite (the round object) to move to the right (or set position), along the gradient line by x amount of pixels.

    The way that I count times is:

    every 1 second add 10 to variable "seconds". Whenever the variable "seconds" reaches 60, it goes back to 0 and adds 1 to the variable "minutes" and starts counting again. When "minutes" reaches 60, it goes back to 0 and adds one to "hours". When "hours" reaches 24, it goes back to 0 and adds one to "days" variable.

    Any ideas on how to achieve that? It may be something very simple, I'm just not seeing...

  • if your seconds will go ten by ten

    seconds = seconds + 10

    minutes = minutes + floor(seconds/60)

    seconds = seconds % 60

    hours = hours + floor(minutes/60)

    minutes = minutes % 60

    days = days + floor(hours/24)

    hours = hours % 24

    startposition = 100

    endposition = 600

    sprite.X = startposition + (hours/24 + minutes/1440+ seconds/86400)*(endposition-startpositon)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks very much for the reply,mrcgkh, I appreciate your input.

    This is how it is set up at the moment, but I can also just have it as self.x +1.

    What this does is moving the sprite right from the start and keeps on accelerating, which is not what I want. Removing "Every tick" doesn't help either. My problem is finding the correct condition to trigger the movement itself only when the "hour" variable changes (increases).

    I can make it work really simple like in the below image, however, I want to be able to trigger it by the "hours" variable rather than a flat number. If I change "Every 60 seconds" to "Every "hours" seconds" ("hours" being the variable), it just starts going right without stopping..

    I hope it makes more sense of what I'm trying to achieve.

    Thanks very much again!

  • I've actually sorted it out!!

    I've made another variable equal to the variable "minutes"*60 and referenced in the Every X seconds and now the sprite is moving every 60 minutes (or one hour), as intended!

    Thanks for giving me the inspiration to find the solution to the problem!

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