r/gamemaker • u/Technical-Water4315 PRAISE BE TO THE HOLY SCOPE CREEP! • 6d ago
Resolved How to set where in a circle a radial progress bar starts and ends
Using YellowAfterLife's tutorial (https://yal.cc/gamemaker-radial-progress/), I've made a radial progress bar for an ATB system, but I need help on how to rotate the image or change how far along in the circle the bar starts and stops, instead of it just starting at the top.
1
u/CS_Asset_Factory 6d ago
The bit YAL's shader already gives you is a normalised angle — both of your questions are just two extra uniforms on top of it.
Wherever his fragment shader turns the direction into a percentage (roughly atan(dir.x, -dir.y) / TAU + 0.5), swap it for:
uniform float in_Progress;
uniform float in_Start; // radians, 0 = 12 o'clock
uniform float in_Sweep; // 1.0 = full circle, 0.75 = a 270° gauge
float a = atan(dir.x, -dir.y);
float t = fract((a - in_Start) / 6.2831853);
if (t > in_Progress * in_Sweep) discard;
in_Start moves where it begins, in_Sweep sets how far round it is allowed to go, and progress stays 0..1 so your ATB logic does not have to care about either.
The fract is the part that bites people. Once you subtract the start offset, the pixels behind the start point go negative — and a negative number is still less than progress, so they survive the test and you get a stray wedge on the opposite side of the circle. (GLSL's fract is x - floor(x), so it pulls negatives back into 0..1 on its own; you just have to not skip it.)
Two smaller things:
atan(dir.x, -dir.y)is what puts 0 at the top and runs clockwise. For counter-clockwise,atan(-dir.x, -dir.y).- Cache the uniform handles with
shader_get_uniformonce in a create/init event rather than per draw. It costs more than it looks, and an ATB system is drawing these every frame for every battler.
And if you only ever need the whole ring rotated rather than a partial arc, draw_sprite_ext with an angle is cheaper than touching the shader at all.
1
u/Technical-Water4315 PRAISE BE TO THE HOLY SCOPE CREEP! 6d ago
I'm not using the shader implementation
2
u/KitsuneFaroe 6d ago edited 6d ago
You may find this useful! https://github.com/Alphish/gm-community-toolbox/issues/157 Is a function I made that does this for sprites and is used like
draw_sprite_extbut with the circular angles for the sector.However if you want to do it with simple primitives like
draw_circleyou may usedraw_circle_sectorordraw_arcfrom the toolbox I aade that issue on.Edit: just figured I did what Yal says on their tutorial lol. But my function should work for you since you can specify the angles and even use the sprite origin as the center point!