math help for exp bar

0 favourites
  • 4 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I have three variables to account for I'm having problem getting bar to always be the right size depending on the current exp value

    the bar itself is 170 pixel wide / initial value set to 0

    variable 1 bar.initialWidth = 0

    the player

    exp = 0

    then 5 global values

    lvl1 = 240

    lvl2 - 480

    ext..

    I'm trying to have that bar grow with his exp and max out filling the bar to 170 pixels when the lvl1 exp needed is reached and lvl2 exp is reached ext...

    i have tried something I used on an old game for health

    (Self.InitialWidth + (Math_Boy.exp-Math_Boy.MaxExp)*(Self.InitialWidth/Math_Boy.maxExp))

    but that didn't work granted I changed the way the MaxExp was working but even setting the player to hold both the MaxExp and the exp value didn't work in this case... can't figure out why?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You should use Array, to contain data of levels scope.

    Then, you need variable, to get data from array (CurrentLevel)

    Formula of changing bar's (healthbar, manabar, expbar...) size is very simple:

    Width of your bar / Value you want to reach * Current Value

    So,

    Then, if value of your CurrentExp is greater or equal to scope, you need to make a little check:

    For example:

    Array:

    x1 = 240

    x2 = 580

    CurrentLevel = 1 (So the scope is 240)

    CurrentExp = 260

    It will:

    • check if CurrentExp > Array.at(CurrentLevel) (260 > 240)
    • set CurrentExp to CurrentExp - Attay.at(CurrentLevel) (260 - 240 = 20)
    • add 1 to CurrentLevel

    You will get level 2 and 20 exp with it

    I hope I have explained completely enough

  • wow thank you soo much that was very insightful

  • oh i was too slow, anyway here is another solution with the dictionary

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