Resize on spawn

Get help using Construct 2

Post » Fri Jun 14, 2013 5:56 am

Hi guys,

Given an object (a sprite) I added an event on the start of the layout to generate a few of these. The problem is that I want to generate them at different locations and different sizes. The location is easy as it's part of the create object parameters but how do you size the sprite instances at runtime? For example let's say my sprite is 32x32 and I want to generate 5 of this size and 5 at 64x64. I can't imagine I have to create two different sprites in my layout and generate each size separately. The create object doesn't give me back an ID or something so I really can get back to the object to set any properties except going through all of them.

Thanks.
B
17
S
5
G
2
Posts: 39
Reputation: 1,846

Post » Fri Jun 14, 2013 6:59 am

Cant you use Instance Variables to keep track of each new Object as its spawned?

for example....add a instance variable that tracks the Size of the object and the number of larger sized objects you want

and then add an extra event that says...

# of Spawned objects < 5 @64x64 ..On Object Created/spawned

-> Set size 64x64
-> Add # of spawned 64x64 + 1

etc

once the number of 64x 64 is reached no more should spawn at that size..

fairly straightforward

and if you really need to lock it down...put a 'For Each'(object Spawned) condition in there as well....
mystazsea2013-06-14 07:00:23
When in doubt..or you are lost in a Zombie apocalypse or someone is giving you a hard time..Remember one thing..... Read the Construct 2 Manual..it will save your life.:)
B
35
S
13
G
8
Posts: 318
Reputation: 7,685

Post » Fri Jun 14, 2013 1:02 pm

@mystazsea I thought about using instance variables and the On created event which looks like the only way to do it. However the example I gave wasn't really concrete enough.

The sprites are blocks and there can be say 5 sizes (32x32, 32x64, 64x64, 128x32, and 128x64). Given a level I want to spawn a random number of each types. I thought I could create a single block (32x32) then spawn it and size it based on say a "blocksize" instance variable (which would be 0-4).

For example:
Level 1: [email protected], [email protected]

This would produce 3 blocks sized to 32x64 and 2 blocks sized to 128x32.

To set it up I use System => On start of layout and set the instance variable (blocksize) to 1 then spawned 3 objects then set it to 3 and spawned another 2 objects.

Then I setup block On created with a condition when blocksize == 1 and the action to set the size of the block to 32x64.

This didn't work as everything created is still the original size.

Without having to create a different sprite for each size I'm not sure how I can do this.

Why is setting the size on each instance dynamically so hard? I'm sure I'm doing something wrong here.

Thanks.
B
17
S
5
G
2
Posts: 39
Reputation: 1,846


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 21 guests