Javascript function "increase level bar for a game (percentage or pixels)"


(Alessio Brunelli) #1

Hello people,
someone would be so good as to tell me if there is a function of javascript that will allow me to increase the size of a shape in different percentages to each action? For example, increases by 30 px then 15px then 20px.
i would need to make grow a level bar for a game in percentage (or pixels)
Tks very much


(Mark Hunte) #2

Hi Alessio,

There was a percentage counter that I was playing with a while ago.

have a look at this and see if it can be adapted to your needs.


(Hans-Gerd ClaĂźen) #3

why not use a timeline¿ gototime or continue playing …
it’ll work for simple usecases


(Alessio Brunelli) #4

Beautiful this feature, but I would serve something that functions as I described in the example.
This is only a sample image.
Tks guys :wink:


#5

Hi Alessio @ibelievecorporation

I think for simple case use Hans’ suggestion is a good one. But, if you really need to manipulate using Javascript (not Java that’s something different :wink: ) then have a look at this. It’s a simple example showing a change in the “progress” div’s width when inputting a number into a text field.

https://jsfiddle.net/69q3ea95/16/

You can change the action to whatever you want. A button click, a mouseover, etc.

D


(Alessio Brunelli) #6

Thanks, sorry i mean javascript. :sweat:
I did not mean to enter numbers in a text field.
The game provides the different scores, each element is associated with a value.
Imagine a pinball with elements that mark different scores. Instead see a number like running score I need something to make me see the score with a bar score, not a number.
So if the first try can do a partial score of 0 points or 35 points (only 2 possible scores) at the second attempt, the bar will start from the result that comes from the first attempt.


(Hans-Gerd ClaĂźen) #7

the example works, you just have to adapt it by adding the event you wanna catch to increase the progressbar


#8

The “entering numbers in a text field” is just one of many ways to increase the bar. You can do it onclick or use your own function. This is just to show you a way of achieving what you want. I don’t really have the time to write a specific script for your specific needs. If you supply a document showing what you’ve done then people will try and help you.

You asked for

I told you and gave you an example

Again I showed you how to do this.

Instead of an input area you can change it to a button or like I said a specific function. So, in your example of a pinball game. When your function for the action of hitting an element is called you can include the method above so that a bar will increase by a specific amount and the text will reflect that.

Or you could even go to a time in a timeline to achieve a similar effect like @h_classen said. Just have a symbol that represents the bar and play an animation when an element is hit.

D