Create instance of type stored in a variable?

0 favourites
  • 3 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • 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

  • 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...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)