• 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!

{SOLVED} Circle and direction

N

NoFontNL

Guest
I have a circle, divided into optionCount parts. How would I go about drawing sprites on each
center of one part.

The sprites are located in the variable item[n] where n is the sprite index.
So item[0] would be sprite 1 in above image.

How do I calculate the positions of the sprites?

I wanted an universal method which works with every optionCount.

I thought of using
Code:
for (var i = 0; i<optionCount; i++){
      var dir = i/optionCount*360 + 1/optionCount*360/2;
      draw_sprite(item[i],0,x+lengthdir_x(128,dir),y+lengthdir_y(128,dir));
}
But that doesn't work. Any help would be appreciated.
 

NightFrost

Member
Get item[N] where N is floor(direction/(floor(360/optioncount))).

EDIT: and your movement direction is point_direction(0, 0, vspd, hspd), calculated before collisions if you're wanting to face direction player is trying to move, as opposed to whatever actual movement was executed.
 
Last edited:
N

NoFontNL

Guest
I want to calculate the direction with item[N] and with itemCount. I already know what itemN is and what itemCount is.
 
Code:
var chunk_dir = 360 / optioncount
var start_dir = chunk_dir / 2
for (var i = 0; i<optionCount; i++){
     cur_chunk = start_dir + (chunk_dir * i);
     draw_sprite(item[i],0,x+lengthdir_x(128, cur_chunk),y+lengthdir_y(128,cur_chunk));
}
If I'm figuring that out correctly.....

You should now see it moving around, and drawing the sprite at each chunk.

So:
optioncount = 4
chunk_dir = 90
start_dir = 45;
first sprite = 45 + (90 * 0) = 45
second sprite = 45 + (90 * 1) = 135
third sprite = 45 + (90 * 2) = 225
fourth sprite = 45 + (90 * 3) = 315

optioncount = 6
chunk_dir = 60
start_dir = 30;
first sprite = 30 + (60 * 0) = 30
second sprite = 30 + (60 * 1) = 90
third sprite = 30 + (60 * 2) = 150
fourth sprite = 30 + (60 * 3) = 210
fifth sprite = 30 + (60 * 4) = 270
sixth sprite = 30 + (60 * 5) = 330

etc
 

Yal

🐧 *penguin noises*
GMC Elder
X position: lengthdir_x(circle_radius/2,desired_angle)
Y position: same except use lengthdir_y instead.
 
Code:
var optionCount = array_length_1d(item); <<<<<<<<<<<<<<<<
var chunk_dir = 360 / optionCount
var start_dir = 90; <<<<<<<<<<<<<
for (var i = 0; i<optionCount; i++){
    cur_chunk = start_dir + (chunk_dir * i);
    draw_sprite(item[i],0,x+lengthdir_x(128, cur_chunk),y+lengthdir_y(128,cur_chunk));
}
One last thing that occurred to me about making this more "automated" is integrating the array length of 'item' into the process, and also starting the angle at 90 degrees. The last one doesn't really make any difference to how it all works, but does ensure that each display starts from the top (I forgot that 0 degrees is at mid right)

Once I really got into thinking about it there was the question of how I'd like a radial menu to display. Like: 3 items using the above gives a triangular placement, and would I prefer those three items to be more grouped together? But that ought to be fairly easy to figure out for yourself, if you decide to specialize it.
 

Yal

🐧 *penguin noises*
GMC Elder
One last thing that occurred to me about making this more "automated" is integrating the array length of 'item' into the process, and also starting the angle at 90 degrees. The last one doesn't really make any difference to how it all works, but does ensure that each display starts from the top (I forgot that 0 degrees is at mid right)

Once I really got into thinking about it there was the question of how I'd like a radial menu to display. Like: 3 items using the above gives a triangular placement, and would I prefer those three items to be more grouped together? But that ought to be fairly easy to figure out for yourself, if you decide to specialize it.
Easy: get the angular step based on 360/(array size). Have a maximal possible step size... e.g. 45 degrees if you want the pie-slices to only start autoadapting to the radial size once you have at least 8 of them.
 
Easy: get the angular step based on 360/(array size). Have a maximal possible step size... e.g. 45 degrees if you want the pie-slices to only start autoadapting to the radial size once you have at least 8 of them.
Yeah - it didn't take long to figure out how that would work. I guess it comes down to personal taste as to how you have it set up. Maybe the game doesn't pause when in a radial menu, so having them grouped together makes it easier to choose between them. Or if the game does pause, or at least slow down (as some do), then having them spread out can be okay and doesn't leave an empty amount of space. A question of aesthetics versus ease of use, but as this has been marked as solved I guess that's a question for another day......
 
Top