Create instance of type stored in a variable?

Get help using Construct 2

Post » Sat Sep 26, 2015 3:18 pm

I have a palette of different blocks (pBlock1, pBlock2 etc) in a family called Palette. "Palette" has a family instance text variable called blockType that varies depending on what type of block they should create when clicked on so pBlock1 has the variable set to "block1" and when it is clicked on I want it to create an instance of block1.

it would be like this: If mouse clicked on Palette -> Palette spawn instance (self.blockType)

is this possible or do I have to:
If mouse clicked on Palette
If Palette.blockType = block1 -> spawn instance block1
If Palette.blockType = block2 -> spawn instance block2
If Palette.blockType = block3 -> spawn instance block3
If Palette.blockType = block4 -> spawn instance block4

Imagine what this would look like if I have a palette of 50 (or more) different types of blocks.

There has to be a better way.. if anyone knows please do tell :)

Thanks
B
31
S
10
G
6
Posts: 258
Reputation: 6,749

Post » Sat Sep 26, 2015 6:58 pm

one Block.Sprite with 50 frames...?

If mouse clicked on Palette-> spawn Block.Sprite
...................................................set frame to int(right(Palette.blockType,1)

or something like that...
Image
B
63
S
23
G
7
Posts: 1,479
Reputation: 10,784

Post » Sat Sep 26, 2015 7:14 pm

korbaach wrote:one Block.Sprite with 50 frames...?

If mouse clicked on Palette-> spawn Block.Sprite
...................................................set frame to int(right(Palette.blockType,1)

or something like that...


Nope not like that.. but it doesn't matter, I scrapped the whole thing. I'm trying to build a level editor but using sprites to build an entire level would be too resource intensive. Better to figure out a way to do it with tilemap. Thanks anyway
B
31
S
10
G
6
Posts: 258
Reputation: 6,749


Return to How do I....?

Who is online

Users browsing this forum: mrkaio, muquia, tarek2 and 2 guests