Choosing right object using two families.

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

    I'm trying to make an enemies units, using a two family for that.

    Enemy unit made of two objects:

    Base (sprite) - using for all interaction with other game bases.

    Art (sprite) - using for visualisation of current enemy activity.

    I have a two family, Base for all bases sprites and Art for all art sprites.

    Also i'm using a containers for each type of unit and put into that containers base and art sprites.

    So container 1 contain (base1 and art1).

    Container 2 (base2, art2).

    Container 3 (base3, art3).

    Art have a variable "baseUID".

    When art sprites created i'm put into that variable value of base.UID. So i'm can anytime compare value of base.UID and art.baseUID for choosing correct base and art of unit.

    Bases have a variable "currentAnimation". I'm seting this variable when i need to play a certain animation.

    Then i'm set animations for "Art" based on base.currentAnim value.

    And here i have a problem with correctly chsoosing of "art" sprites.

    This is an example: drive.google.com/file/d/1QhrTKNo-1PSF3KfJ9YDlk0dw3sBmZI2K/view

    As you can see (in debug mode of cource) the variable "currentAnimation" get correct value.

    But animation of art is incorrect.

    Help me please to understand what i'm doing wrong.

    Hope my engrish is understandable and i'm discribed my problem well.

  • Generally, when you pick multiple instances by UID, you need to use "For Each".

    So change your code to this:

    .

    Also, if you only have a few enemy types, it may be easier to combine them into two sprites. (combine art1, art2, art3 into one "art" sprite, and base1, base2, base3 into "base" sprite)

    This way you will not need to use families and you'll be able to fully benefit from the use of the container. You will no longer need the baseUID variable as instances in containers are picked automatically.

    Of course you will have to add another variable "EnemyType" and name your animations like "Walk1", "Walk2", "Walk3" for different enemy types.

    So your events may look like this:

    Base Platform is jumping -> Art set animation to "Jump"&Art.EnemyType
    

    Simple!

  • Generally, when you pick multiple instances by UID, you need to use "For Each".

    Yeah, thanks. I'm already deal with that problem. I'm just tryed everything, and this one accidentally work perfect.

    drive.google.com/file/d/1eHDa-76T-BGPuREzOcwLVrIZ2xJEM1pI/view?usp=sharing

    Also, if you only have a few enemy types, it may be easier to combine them into two sprites.

    I'm may what i'm may. But what i'm need i'm described in a topic. There only example so simple, real project not so. 15 different units with 17 animations each. But thanks anyway.

  • "For each" loops are quite slow. If you are planning to have 17 animations, with this approach you'll need at least 19 loops, which may cause performance issues. So I suggest to do everything in one loop (see the screenshot in my previous comment)

  • "For each" loops are quite slow. If you are planning to have 17 animations, with this approach you'll need at least 19 loops, which may cause performance issues. So I suggest to do everything in one loop (see the screenshot in my previous comment)

    Already did thanks.

    But now i'm have another issue with "Trigger once" condition.

    When i'm clicking on unit i'm setting up currentAnimation to "Clicked".

    Next, when setting art animation

    base curAnim = Clicked -> art set animation to Clicked Trigger once

    It work only for first clicked instace of object. The others repeat they animation. How do i can fix it?

    Example: h*t*t*p*s://drive.google.com/file/d/1AIIYMTTczNN2GW5z6HaDPUCPPlCV3hke/view?usp=sharing

  • Don't use "Trigger once" inside loops. It doesn't work per instance.

    Here is an updated capx

    dropbox.com/s/6nkjp62fgk2wa4i/Family3.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This method dont alow to loop animation that must be looped. Like walk.

    But combining your and my method together is a solution for my issue. Many thanks.

  • Just set looping in animation properties.

  • Just set looping in animation properties.

    Yeah. Didn't think about that solution.

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