You are not logged in.
Pages: 1
I'm trying to create 10 buttons in a row, here's what I have in a controller Create event.
for (i=1; i<=10; i+=1)
{
instance_create(300 + 48*(i-1), 300, obj_button_add)
}
This does what I want but the 10 sub-images on each instance created spin around.
How can I create 10 individual buttons each showing only one sub-image and each having it's own id?
ie
Button_1,sub_image_0
Button_2,sub_image_1
Button_3,sub_image_2
So that I know which button the mouse pressed.
I have tried all sorts of ways but I've gone round and round so much that I'm now dizzy.
Offline
I'm trying to create 10 buttons in a row, here's what I have in a controller Create event.
for (i=1; i<=10; i+=1) { instance_create(300 + 48*(i-1), 300, obj_button_add) }
This does what I want but the 10 sub-images on each instance created spin around.
How can I create 10 individual buttons each showing only one sub-image and each having it's own id?
ie
Button_1,sub_image_0
Button_2,sub_image_1
Button_3,sub_image_2So that I know which button the mouse pressed.
I have tried all sorts of ways but I've gone round and round so much that I'm now dizzy.
var i;
for (i=0; i<=10; i+=1)
{
with(instance_create(300 + 48*(i), 300, obj_button_add))
{
image_index = i;
image_speed = 0;
MyID = i;
}
}
you can look at MyID in your code... or image_index since in this case it's the same. Note i starts at 0 now...
Offline
Thanks for that, didn't expect to get a response that fast!!
Damn near got the answer before I'd finished the question.:lol:
Ok I placed the code in the create event and it placed 10 buttons on screen each with a different image_index.
But how do I keep the information so that I can use it later in the game.
For example if I click LMB on button 5 it will say you pressed button 5.
That's not the effect but if it does that then I know it works and can then add better events for when a particular button is pressed.
Edited:
Used this
global.MyID[i] = i;
which gives each button a number that can now be used else where in the game.
I think it's the right way to do it?
Last edited by Anybloodyid (2011-03-20 15:44:43)
Offline
Pages: 1