How do I spawn specific sprite from family?

0 favourites
  • 10 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hello,

    In this capx is easy thing similar to:

    IF family.ItemId = 1 THEN spawn sprite from family with ItemId 1[/code:1vca20x9]
    But it works differently. It will spawn just whole family and that means it will spawn random sprite from family. Regardless on number in ItemId.
    Question: is there any way how to spawn sprite with instance variable ItemId = 1 from family?
  • Sadly, Construct 2 doesn't allow you to dynamically name the sprite you want to create. I have implemented a work around using a Function. You can check it on the following .capx:


    Left-click adds blue squares

    Right-click adds yellow squares

    Middle-click adds random item from family

  • Thanks for reply.

    Your solution works but still there is needed to specify blue and yellow sprites separatedly. If I will have 150 sprites then I need to use 150 events.

    Really there isn't any other way? For example foreach all objects in family and check ItemId or foreach all completely all items or similar thing? I can't believe that such genial program like Construct 2 does not have such thing

  • I never understood why this wasn't supported: it seems trivial, and would be very useful. Am I missing something?

  • Same here... I don't know why you cant create "Sprite"+id. But, unfortunately, you can't.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Another work around people sometimes use is making each sprite as an animation frame for the same sprite instead. And setting the frame according to the id.

    For instance. A sprite that has 150 animation frames, each with a different sprite. Or in your example, a sprite called square that has frame 0 as a blue square and frame 1 as a yellow one.

  • There is a third party add-on "nickname". You can look that up.

  • Using sprite with animation frames is possible probably for display only. But if I want to display sprite with ItemId = 150 and do damage defined in that sprite then I think solution with animation frames not help. Also I need to have two same sprite images on two places and edit them on two places.

    Nickname plugin looks good. It is still not best thing (you need to insert picked items into family and work with that family = same object in two places) but I think it will be still better than 150 conditions.

  • (you need to insert picked items into family and work with that family = same object in two places)

    Hi can you explain what you mean by this? I've just started experimenting with Nickname but there doesn't seem to be a drawback using a family this way.

  • codah: look at attachment. You need to have one your family (Items) but also new family (SelectedItem) with exactly same content. When you will pick one sprite and you want to do with it something (rotating...) you will access it through family SelectedItem.

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