The best way to dynamically spawn a list of buttons?
-
I am wondering if anyone has any good idea on how to dynamically spawn a list of buttons.
These are the two ideas I have came up with:
-
Use a timer with a slight delay and set an attribute that the label will set to once spawned (pretty slow)
-
Use Loop behaviour and use receive and broadcast behaviours based on the label's location to send it the information
These are both pretty bad workarounds, so does anyone know anything better, or will I just have to wait for hyperPad to add support to object referencing?
-
-
@kamdroid I just did some playing around, even looping with broadcast won't work because the object can't receive the message because the loop is too fast for the 2 behaviours (spawn and broadcast) to work together. I wouldn't dynamically spawn buttons and assign them a value based off their position though, I'm not sure how yours works but for mine I'd use an array that's storing all the button values (some sort of marker or ID for what the button is going to do). I'm nearly done with one that would probably spawn 60 buttons per second, I'll give the project link.
-
@kamdroid I give up, spawning was too slow and behaviours that I wanted to be activated after the object was spawned (like broadcast message) were happening before the object finished spawning. So yeah, you'll have to make it spawn them slowly.
-
@kamdroid I don't understand what you mean by dynamically spawning a list of buttons.
What is dynamic about them? What is changing?
What is a "list of buttons"?
If I can understand these things, I think the dynamic system I have, for showing dynamic scores on objects, will work. But I don't think I fully understand what you're wanting to do.
In this video (below), notice the scores showing up on the hit discs, inside them, they're dynamically generated, and instantly placed (from pre-spawned pool, for speed) at these locations. This can handle dozens of them, all with different scores, as each hit increments the scoring. Hit a disc 1x = 500, 2nd time = 750, 3rd = 1000, etc...
Similarly, the Hexagons in the background, when rolled over, start at 100 points and go up for each rollover after that. And, again, this is all specific to the objects, and dynamically placed, from a pool. Each hexagon "requests" a score to show upon itself.
password = spinjump
-
@deeeds This is what I mean:
-
@aidan-oxley strange - I use this method for dynamically spawning apps in my new OS sim.
-
@kamdroid Yeah, you need a delay for it, spawn object then wait maybe 0.1s then broadcast a message or something for it's data. Actually, now that I think about it, you could spawn them all at once (using a loop) then once you're sure they have all fully spawned, broadcast a single message with an array for the value containing the data for every button based on it's position. All buttons receive the message and using their position they find the data relevant to itself.
-
Create an example of a button object in the Editor. Sprite image, and the text object required to fill out this button. I use images for button objects and the text because Sprite Sheets and bitmap fonts don't currently work in hyperPad. This means I have a graphic element for a score of 100, 200, 250, 500 etc. You need these images for button1's text, button2's text, etc.
You only need one button graphic.
You also need a dummy object that's going to represent the eventual locations of your buttons. This dummy object needs a tag that defines it as a dummy object. Duplicate this as many times as you need, and place it in your scene where the buttons will go.
When your game starts:
have an array get the position of each of these dummy objects, and store their x and y in respective arrays, as it finds them. It will do this in a reliable order, so X and Y won't get confused. But you do need two arrays. Dummy_y_positions and Dummy_x_positions, or something like that.
Delete the dummy objects, they're no longer of any use
Run a for loop that's the length of the array, and spawn a button object and a text object for each of your buttons, and position them, in this for loop, at 0, 1, 2, 3, 4 etc on the X axis, via their index from their relative array positions (where you're going to get their eventual positions).
Now the tricky part.
Inside each of the text and button images is code that merges the name you give the buttons with their individual index in the array. use this as a receiver string for a message receive behaviour in each object that blends this text together on spawn.
Now you have a reference mechanism between each object at any given position, and an array that lets you call into any specific one of them and tell it to do as you please.
And pray that they introduce proper referencing and instancing in the next update()
;)
-
@kamdroid what data are you wanting to be sent to each button?
-
And what are the buttons controlling/ triggering?