createobject in loop

Get help using Construct 2

Post » Wed Mar 19, 2014 2:12 pm

im running a for loop to create a bunch of icons, i have a container as start object, nowin first loop object copies the container object, second time in loop it copies the newly created object instead of the original container, so all icons created are the same, not the effect i desire, is there some way you can create object based on name($i_icon) or similar so that new objects are unique?
B
9
S
2
Posts: 76
Reputation: 709

Post » Wed Mar 19, 2014 3:26 pm

It depends on your project, so can you write your question in more detail?
B
23
S
8
G
1
Posts: 172
Reputation: 2,780

Post » Wed Mar 19, 2014 6:12 pm

Best way to get help:

1. Tell us what the expected result is
2. Tell us what is actually happening
3. Post .capx or image of events (you can use the attach button when posting)
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Wed Mar 19, 2014 8:22 pm

heres a image of the said code:
the create object creates objects but not any new instances just copies of previous instance.
i=0; num_games=5;
You do not have the required permissions to view the files attached to this post.
B
9
S
2
Posts: 76
Reputation: 709

Post » Wed Mar 19, 2014 10:15 pm

Only error I can spot is that the For loop already adds 1 every time, so you don't need that "Add 1 to i"
"i" is just the name of the loop, not a variable
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Thu Mar 20, 2014 2:32 am

kaiko, i think you can use array for this problem. you for loop seems to right but it is taking the default value. Right. use array, say you are having 20 icon, make an array list and call one by one. simple !!!!!
B
7
S
1
G
1
Posts: 79
Reputation: 716

Post » Wed Jul 01, 2015 6:59 am

sorry but i am using an array, the problem is that createobject doesnt create a unique object, so when i load image from url, all game_icons get this image., since im creating a menu with different icon for each game ,now i get same icon for all games.not exactly what i want
B
9
S
2
Posts: 76
Reputation: 709

Post » Wed Jul 01, 2015 8:55 pm

That's the way "load image from url" works. It will update the image for all sprites. You'd have to load the image into a different frame.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Wed Jul 01, 2015 10:55 pm

there must be a work around, how can you display 40 different images fetched dynamically without creating 40 objects on stage?
B
9
S
2
Posts: 76
Reputation: 709

Post » Thu Jul 02, 2015 12:04 am

kaiko wrote:there must be a work around, how can you display 40 different images fetched dynamically without creating 40 objects on stage?

There are no work around, you can create 40 objects or you can add 40 frames to your object and then make a functionality that load them into the correct frames. Regardless of which way you do it, none of them are going to be pretty.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Next

Return to How do I....?

Who is online

Users browsing this forum: Congrats2u, Darknessed, Magistross, worm1, Yahoo [Bot] and 28 guests