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

Windows Menus

C

Chungsie

Guest
Ok, I am using objects for menu choices. and an arrow for selection.



Choice.png so this is the static arrow, I want when the player does not change choices. Choice-between.gif when the player moves between the menu object choices I want that animation of the arrow. After a few seconds, I was hoping it would play an audio recording specific to the current chocie selection, only once, but again if the player returns to that choice. I am handling the menus as rooms. How can I set this up to work well for my game? Also, I plan on having animations for the icons when a choice is made, but that is a future endevor as it would involve a great amount of animation. mostly as cutscene movies. Is there an easy way to do this?

I want the player to be able to interact with the menus using either keyboard or game pad if the gp is plugged in. Like is it as simple as checking the ycoord of the arrow and comparing it with the objects?
 

Hyomoto

Member
It can be. Based on what you are doing, you'll probably make your cursor to be an object. In that case you most certainly could have it's behavior dependent on it's y coordinate:
Code:
if y == 240 and keyboard_check( vk_enter ) == true { // do }
There are quite a lot of ways you can do this that are a little more elegant, and more importantly easier to maintain, but as a first try you are certainly on the right track when thinking about this stuff. The benefits of having your cursor be an object is you can have it do whatever you want it to do, you just have to write the code for it. I'm not entirely sure from your description entirely what you are trying to make happen but perhaps I can still help a little by trying to break down what you want to do. I'm guessing you want the static arrow when the cursor hasn't moved, but you want it to spin when it does, is that right? For this you could use an alarm:
Code:
if alarm[ 0 ] == - 1 { draw_sprite( cursor_arrow, 0, x, y ) }
else {
  draw_sprite( cursor_arrow, alarm[ 0 ] mod sprite_get_number( cursor_arrow ), x, y );
}
In this case, when you want the cursor to spin, you would just set alarm[ 0 ] to # of rotations * number of frames in the animation. When an alarm is -1, it is no longer counting down. So, we check and say, this alarm isn't running so let's draw the static arrow. For the animated cursor we are saying, the timer is running so let's make the image we are displaying based on that. What I've done is used a modulo operation to get the remainder of the alarm when divided by the number of frames in the cursor_arrow animation. That means we should get a 0 - sprite_get_number( cursor_arrow ) - 1 result which will display that frame of animation. So, the higher the number you use for your alarm, the more times it will spin, but most importantly it will stop when the timer reaches 0. It's a very simple and quick way of handling it, though I suspect you'll have to tweak it for the exact result you want ( as it's speed might be a bit high ).

As for having it do something based on it's y position, I don't fully recommend this because of how easy it is to screw it up. What I would say is you should have it's y position based on what the player has selected.
Code:
selection = 0
Then draw your cursor based on that:
Code:
draw_sprite( sprite_index, image_index, 64, 128 + selection * 32 )
And finally you can then make decisions on that, instead of the y position:
Code:
if selection == 0 { //do }
That's quite a bit more manageable and allows you to move the cursor around without breaking a bunch of code in the process. As you can hopefully see, the position of the cursor will change as selection does ( it assumes your menu items are evenly space apart ), and to change the position of the cursor on screen you just have to change those draw values to wherever it is you need it to show up. That's quite a bit easier than managing absolute positions of each selection. I hope this information helps you. Have fun and keep coding!
 
Last edited:
C

Chungsie

Guest
thanks
I was not able to get a new animation to stop after 4 frames for some reason. even using the advice I got on stopping an animation did not work... I don't understand why. the blood splatter sfx is a place holder for now, need to work on a better one later.
 

Hyomoto

Member
The most likely reason your cursor doesn't stop spinning is because it's being managed by GM's built in code. By default an object will loop through all the frames of a sprite that is assigned to it. You can change this by either setting image_speed to whatever you'd like, or 0 to stop if from going through the cycles. However, when you stop the image_speed you need to make sure to set image_index to the first frame of your animation, which I assume is 0. To manually control the animation you need to handle it yourself, the following code is equivalent to 'draw_self()'.
Code:
draw_sprite( sprite_index, image_index, x, y )
If you used this in your draw event:
Code:
draw_sprite( sprite_index, 0, x, y )
It would only draw frame 0, ever. So, if you want to control the animation, you can either manipulate image_speed and image_index and rely on the built in capabilities of GM, or you can keep track of it yourself:
Code:
var _index alarm[ 0 ] mod sprite_get_number( sprite_index );
draw_sprite( sprite_index, _index, x, y );
In this case, the frame that is drawn is based on what the result of alarm[ 0 ] is, as I mentioned above, which means it will only animate while alarm[ 0 ] is counting down. However, you can change _index to be equal to whatever you want to control your animation. Maybe this will help with your problem, good luck!
 
C

Chungsie

Guest
that would be perfect, except that the animation speeds are random between 1 and 10...

edit: 1/1-1/10
 
Top