1
\$\begingroup\$

I am trying to make it so that when I click on a button in my games store that the current button changes to a new one right where the old one was and then has its own conditions.

ex. Press the button "Add 1/ps - $50", effects applied and now "Add 5/ps - $500" is now the button which will do the desired effect when clicked with conditions met.

How do I go about doing this?

\$\endgroup\$

3 Answers 3

1
\$\begingroup\$

instance_change(obj_anotherButton, true)

First parameter is which object you want to change the current object into.

Second parameter is either you want to execute the create and destroy events in the the new object. (True runs it, False does nothing)

More info at Game Maker Reference

\$\endgroup\$
0
\$\begingroup\$

You want to make 2 different objects, doing it in one would be too complicated. Make 2 different sprites with one having "Add 1/ps - $50" and another with "Add 5/ps - $500". Make sure both of the sprites are the same size and are centered on the same spot. Have your upgrade happen in your code, then call a script (what you name it is up to you)

//Have your code for upgrading your "ps" here.
//Now call your script here. ex: upgrade();

Now in the script, write:

var xx = x;
var yy = y;
instance_destroy();
instance_create(xx,yy,obj_newPsButton);
\$\endgroup\$
0
\$\begingroup\$

By creating and destroying objects, while it doesn't create overhead, it's inefficient. If I'm understanding your question right you want to have a button that changes from a 1 ps bought to a 5 ps bought.

In which case, you can just draw the text on top of the button sprite and change it when the button is clicked.

Drawing

draw_text(x, y, text); 
/* Where text is the variable you change when the button is clicked 
   and x/y are the position of the text on the button */
script_execute(effectApplied); 
/* This being an object var with the data of the script to run */

Then whenever the button is clicked

text = "Add 5/ps - $500"; // Set the new button text
effectApplied = newScriptToRun; // Set the new Script to run

This, in my opinion, is the best way of performing this. If you want the button sprite to change then you can just have each of the button images be included as subimages in a single Game Maker Sprite and just change the sprite_indexto the new sprite then change the effectApplied script var.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .