• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Smart bar [Solved]

wilmer

Member
Hi :
Look, I don't remember what game I have seen this in, what happens is that I need a kind of smart bar like in the gif that I attached here; The bar has a "piece" that goes from one side to the other and if the "piece" touches at least one pixel of the purple square in the center, it will execute the code that I want to put on it. It is for a fighting game and if my enemy knocks me down, my character will be knocked out and this bar will appear so that when pressing a key the "piece" will stop at that moment.

Maybe I can do it but with simple functions like "place_meeting". I would like to know if you have a cleaner code idea and if you know what this type of bar is called, I would appreciate it.
ezgif.com-gif-maker (1).gif
 

obscene

Member
You wouldn't use collisions for something like this. Break it down to the math...

First, code the back and forth motion using numbers. You might have a value that fluctuates between -1 and 1. Add a value to it each frame until it reaches 1, then start subtracting the value instead until it hits -1 and repeat.

Second, code the button press. If the button is pressed and your value is within some range of 0 (for example, -0.1 and 0.1) then it's counted as successful.

Third, draw it to screen. The background is easy. Set the origin to the center. Then the moving bar. Draw the bar's x position using your first variable. You know it goes between -1 and 1, so draw it at x+value*however_wide_your_graphic_is*0.5;
 

wilmer

Member
You wouldn't use collisions for something like this. Break it down to the math...

First, code the back and forth motion using numbers. You might have a value that fluctuates between -1 and 1. Add a value to it each frame until it reaches 1, then start subtracting the value instead until it hits -1 and repeat.

Second, code the button press. If the button is pressed and your value is within some range of 0 (for example, -0.1 and 0.1) then it's counted as successful.

Third, draw it to screen. The background is easy. Set the origin to the center. Then the moving bar. Draw the bar's x position using your first variable. You know it goes between -1 and 1, so draw it at x+value*however_wide_your_graphic_is*0.5;
Thanks for responding so quickly, well I would do it more or less like you told me, is what I had in mind what happens is that I do not know if it will be as accurate as possible, as well as in tutorials that I have seen of platform games where they are needed perfect collisions and you have to find the fit. I'm going to put the post as Solved.
 

obscene

Member
You can make it as accurate as you need. You control the speed. You control the range within you mark it successful. You could make it +/- 0.01 if you want.
 
I have been working on some eh 'similar' things. If you like I can send you some code and talk you through it. If not just considder the following.
  • What is the width of the object
  • What is the height of the object
  • How fast does the slider move
  • Which portion of the slider contains the area of interest
  • What is the width of the area of interest
  • What is the height of the area interest
  • What is the offset of the area of interest
  • How will the surface be interacted with (A click maybe)
  • What is the sprite of that variable
I could go on. And I'm sure I will get hassle for this. But The way I code things is to list out as many variables as I can then it makes it easier to think about later.

I have spent far too much time on these kinds of problems so I know them quite well.
 

wilmer

Member
I have been working on some eh 'similar' things. If you like I can send you some code and talk you through it. If not just considder the following.
  • What is the width of the object
  • What is the height of the object
  • How fast does the slider move
  • Which portion of the slider contains the area of interest
  • What is the width of the area of interest
  • What is the height of the area interest
  • What is the offset of the area of interest
  • How will the surface be interacted with (A click maybe)
  • What is the sprite of that variable
I could go on. And I'm sure I will get hassle for this. But The way I code things is to list out as many variables as I can then it makes it easier to think about later.

I have spent far too much time on these kinds of problems so I know them quite well.
Hello Daniel Mallett, I am interested in everything you said is exactly the bar shown in the comment below, in my case it is for mobile devices and the resolution is 1280 x 720p, but I am a Graphic Designer and I can recreate it to my liking Any editable or code that you share with me interests me more the part of the code, probably instead of a key, use the function to detect keystrokes in any area of the device screen, so if you share the code with me, I would appreciate it very much.
 
Ok, no problem give me a few hours I'll dig it out when I come back from my business. I hope what I have is what you looking for. Hopefully, I haven't miss understood.
 
Before I send you the code do you have any special requirements.
  • Do you need multiple stop areas or just one
  • Vertical toggling (The slider can be vertical when a variable is toggled)
  • Do you want the arrow to speed up when it inside the action area (I'd say yes)
  • Anything else
I'm almost ready now if you are still interested. There are lots of subtleties I can add but I have some base code so you can have a look. Do you want me to give you a bitbucket link, post the code to the site directly, or put the project on a cloud service?
 
Last edited:

wilmer

Member
Before I send you the code do you have any special requirements.
  • Do you need multiple stop areas or just one
  • Vertical toggling (The slider can be vertical when a variable is toggled)
  • Do you want the arrow to speed up when it inside the action area (I'd say yes)
  • Anything else
I'm almost ready now if you are still interested. There are lots of subtleties I can add but I have some base code so you can have a look. Do you want me to give you a bitbucket link, post the code to the site directly, or put the project on a cloud service?
Well, the truth is that I don't have any special requirements, it seems that you know a lot about this, I'm sure what you send me will help me, but if you want to add more things, I leave you my answers to your questions below.
Q: Do you need multiple stop areas or just one
A: I want the arrow to measure the maximum width of the area where it should stop, it would be a single stop area in the center.
Q: Do you want the arrow to speed up when it inside the action area (I'd say yes)
A: Yes, as soon as this bar is instantiated
Q: Vertical toggling (The slider can be vertical when a variable is toggled)
A: My game is horizontal only, I would not use vertical toggle or rotation.
Anything else
Q: I'm almost ready now if you are still interested. There are lots of subtleties I can add but I have some base code so you can have a look. Do you want me to give you a bitbucket link, post the code to the site directly, or put the project on a cloud service?
A: I did not know bitbucket, but it can be in any page if it is too much code but even in a notepad it works for me.
 
Last edited:
I had to link it on google drive as it wouldn't let me upload a 7z. This is a quick implimentation. Ill tidy it up for you in a bit but this works and the logic seems to be sound. If you have any problems with it let me know.

.
 
Top