0 Favourites

Create instance of type stored in a variable?

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

  • Construct 3

    Buy Construct 3

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

    Buy 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)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
223 15,823
Tom's avatar
Tom Construct Team Founder
Unread hot topic
135 14,292
melaniko's avatar
melaniko
Unread hot topic
102 26,811
HERBERT HEINZ's avatar
HERBERT HEINZ