Spawing 2 object, setting size works only the second object

Discussion and feedback on Construct 2

Post » Tue Mar 04, 2014 6:26 pm

Hi,

I essentially wrote the following code, which spawns an object type twice, each time setting a new width. Oddly, only the second time the new width is set. The first spawn retains the width of the object type which was used to spawn the object.

https://dl.dropboxusercontent.com/u/102806407/spawn2.PNG

EDIT: here is the result: https://dl.dropboxusercontent.com/u/102806407/cup.PNG

EDIT: I now spawn three objects, and set a different width for each, but only the last one gets a new width set.

EDIT: Using create object, instead of spawn makes it work:

https://dl.dropboxusercontent.com/u/102806407/createObject.PNG

https://dl.dropboxusercontent.com/u/102806407/cup3.PNG



I wonder why this is?

I'd like to generate "water bars" one ontop of another, to simulate the filling of a cup with water. Since the cup size changes as water is filled each 'spawned" water "bar" needs a new width.

any comments would be much appreciated,

Dan
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Tue Mar 04, 2014 6:54 pm

when creating new objects any setting is done only on the last created object, since you don't always want it to effect all of them, you might want to choose different frames or sizes.
so you'll need to put you're setting after each creation.
if you're settings are the same you can do a repeat or a for each loop.
Image
B
74
S
28
G
12
Posts: 515
Reputation: 12,359

Post » Tue Mar 04, 2014 7:02 pm

get use to working with loops, like this:
On start of layout
Repeat 3 times
create waterbar on
x 560
y 520+(loopindex*20)
waterbar set size
width 300-(loopindex*100)
height 5
Image
B
74
S
28
G
12
Posts: 515
Reputation: 12,359


Return to Construct 2 General

Who is online

Users browsing this forum: Lof, mihirolover and 5 guests