What's the best way to establish the same HUD object (and their different states) for all NPCs?

0 favourites
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Hi everyone!

    In my game, a general HUD object is the same for all NPCs. However, this object has 3 different animations/frames and each NPC has its own instance variable (with the same function) to be associated with these animations. This variable and object expresses the NPC's relationship with the player and, as a state, will vary throughout the game.

    To be practical, it is currently programmed as follows:

    - All NPCs are in the same family

    - There is a single HUD object for all NPCs, which only appears when the player presses UP on the NPC

    - Each NPC has its own variable associated with the 3 animations of the HUD object

    Do you think that each NPC should have its own HUD object or is there a way to keep one for everyone, discriminating in the programming in some way?

    Follow the images of the events below for you to understand better:

    Thanks! :D

  • If you have lots of NPCs but only one HUD can be on the screen at a time, then it's probably better to use one instance of HUD - spawn and destroy, or to keep it off-screen and re-show when needed.

    With not so many NPCs you can do what's easier for you, for example you may create a HUD for each instance, pin it and keep it invisible.

  • If you have lots of NPCs but only one HUD can be on the screen at a time, then it's probably better to use one instance of HUD - spawn and destroy, or to keep it off-screen and re-show when needed.

    With not so many NPCs you can do what's easier for you, for example you may create a HUD for each instance, pin it and keep it invisible.

    Okay, man.

    What I'm trying to say here is that I'm sharing the same HUD object for all NPCs, for facilitating programming when I think it's the easiest method. Each NPC has its own instance variable that determines a specific animation of the same HUD object independently from the other NPCs.

    The most laborious (and conscious) way would be to create X identical HUD objects and program them individually, creating dozens of event lines. I'm trying to optimize this, I just don't know how. :(

  • Hi, can you make a mockup of the result you want to achieve? That could help us to figure the best solution for you

  • Hi, can you make a mockup of the result you want to achieve? That could help us to figure the best solution for you

    Hi!

    All NPCs have the same HUD that appears on his left side when the player presses "up" and shows his emotional state. This emotional state is determined by an instance variable (which each has, with identical names) and expressed by an animation (three in total, associated with each instance variable).

    Thanks! :D

  • So what exactly is the problem? All NPC are in the family, and these instance variables are defined on the family, right?

    When you create the HUD sprite, set its animation to NPC.Variable

  • Hi , below is the mockup you requested:

  • So what exactly is the problem? All NPC are in the family, and these instance variables are defined on the family, right?

    When you create the HUD sprite, set its animation to NPC.Variable

    No. Although all NPCs are in the same family, each has its own instance variable (which has the same name and function).

    I will try this alternative! :D

  • You mean the instance variable is defined on each object, not on the family? You need to move it the family. See this tutorial on how to simplify this task:

    construct.net/en/tutorials/upgrade-object-family-319

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You mean the instance variable is defined on each object, not on the family? You need to move it the family. See this tutorial on how to simplify this task:

    https://www.construct.net/en/tutorials/upgrade-object-family-319

    If a use a Family Instance Variable, it won't work as an individual state.

    Each NPC has its emotional state. It isn't a collective behavior.

  • You will still be able to define a different state in this variable for different NPC sprites.

  • Actually a variable given to a family becomes an individual variable for all the object it contains, you can select an object with that variable inside the family, but also outside it, if you check the object variables in an event you'll see that it shares the variables of the family, it's better than creating a variable for each individual object;

    Back to your mockup, do your NPCs have a variable that define if the player is talking to them? Like a boolean that would be on if talked to, and off if not

  • Actually a variable given to a family becomes an individual variable for all the object it contains, you can select an object with that variable inside the family, but also outside it, if you check the object variables in an event you'll see that it shares the variables of the family, it's better than creating a variable for each individual object;

    I didn't know that! He thought that a family variable would determine the same state for everyone, excluding individuality.

    Back to your mockup, do your NPCs have a variable that define if the player is talking to them? Like a boolean that would be on if talked to, and off if not

    Yeah! I created a Instance Variable now to this action. :)

  • You will still be able to define a different state in this variable for different NPC sprites.

    Thanks, man! I'll try here. I didn't know that.

  • Good, using this boolean you can pick which NPC is currently talking or interacted with (system event "Pick by comparison"), and then create the HUD sprite next to the NPC, and in the same action set the HUD frame/animation based on the NPC variable, for example if variable = Happy, HUD : set animation to NPC.(your variable), and when exiting the dialog, destroy the HUD object

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