Applying Sprite Functions to Drawn Sprites

C

ChaosX2

Guest
Hey Everyone!

I'm trying to program a merchant for my RPG game. I'm stuck on going about the basic menu options; Buy, Sell, Talk. What I'm trying to avoid is having to make each button be an object. The three menu options are displayed using the draw_sprite function. Each of the sprite names are stored in an array.

ex:
menu_option[0] = spr_buyIcon
menu_option[1] = spr_sellIcon
menu_option[2] = spr_talkIcon

Here's where I'm stuck. I'd like for which ever button is selected to run through the animation which is simply a scaled version to simulate a small up an down scale animation (to designate it as selected). What I tried to do was...

if selector value == 1 (for example)
menu_option[1].image_speed = 1;

But it didn't work. I think it's because I drew the sprite rather than create an object and assigned the sprite but am not 100% sure. Would anyone happen to know of a way to make the sprites stored within the array to play it's animation or do I have to resort to using objects?
 

obscene

Member
Well you can't do it the way you are trying, as image_speed is an instance variable and a sprite is not an instance. However you could make that array 2D and store a custom variable to be paired with it... ie, menu_option[1,0]=spr_name and menu_option[1,1]=some_number.

When you draw this, you have to use another custom variable to animate it, and you have to change that variable manually with your custom variable...

draw_sprite_ext(spr_name,sub_image,etc...);
sub_image+=menu_option[1,1];
 
E

Elson Ng

Guest
As mentioned above, you should first use a 2D array to store all the sprites and the animation speed.

Code:
menu_option[0,0] = spr_buyIcon;
menu_option[0,1] = 0.5;
menu_option[1,0] = spr_sellIcon;
menu_option[1,1] = 1;
Next you create only one object which you can change its image_speed and Sprite respectively according to the currently selected value. (Put it in the room or whenever you need it)

You can also dynamically set the value without checking with an if

Code:
// Sprite index
obj_MenuAnim.sprite_index = menu_option[selectedValue, 0];
// Image Speed
obj_MenuAnim.image_speed = menu_option[selectedValue, 1];
Last but not least, use instance deactivate to deactivate the menu object when you are not using
Code:
instance_deactivate_object(obj_MenuAnim);
 
C

ChaosX2

Guest
Thanks for the responses. I ended up using one object and storing it's code in different variables as illustrated below


Code:
op1 = instance_create(324 + (0 * 96), 353, merchantMenu);
op1.sprite_index = merchant_menu[0];
op1.image_index = 0;
op1.image_speed = 0;

op2 = instance_create(324 + (1 * 96), 353, merchantMenu);
op2.sprite_index = merchant_menu[1];
op2.image_index = 0;
op2.image_speed = 0;
    
op3 = instance_create(324 + (2 * 96), 353, merchantMenu);
op3.sprite_index = merchant_menu[2];
op3.image_index = 0;
op3.image_speed = 0;
I then used a switch case statement to decide which option should have it's image_speed set to a number other than 0.
 
Top