health bar as an instance variable

0 favourites
  • 9 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • When you shoot the enemy in the game I'm making, it's health bar goes down. But when another instance of that enemy is created, the health bar is the same. Any suggestions on how to change that?

  • you could make a event to restart de heatlh bar when another enemy appears

  • Your solution is in the title of this thread: use instance variables. When each instance spawns, it'll spawn using the default value of the instance variable, and those variables will be independent of those belonging to other instances.

    If this isn't working properly for you, you might not be correctly picking the instances of the enemy that are meant to lose health: you might be affecting all enemies at the same time.

  • But how? How do I link a picture and an instance variable?

  • Mage213456 - Are you assigning instance variables directly TO the object? I don't mean creating a variable globally in the event sheet, but creating it through the object. Select the sprite/object you want to have the health value instance variable for, then, on the far left of the editor, in the properties bar, look for the instance variable option...that should do the trick for ya.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Assuming you are actually using an instance variable, you need to choose the proper object instance to interact with.

    You can use something like the Pick Instance event, or if you use something like "Is Overlapping Object" or "On Collision with Object" then it will choose the proper instance automatically.

  • Containers are your friends.

    Put the health bar in a container with the enemy. When an enemy is spawned it will have it's own health bar spawned with it, and any time you pick that enemy it will automatically pick it's health bar.

    Just do a for each and loop through your enemies. Each time it picks an enemy, it will also pick that enemy's health bar so that you're only updating just that one.

    Here is a capx (R120.2) that demonstrates what I am talking about.

  • Thanks. I'm still kind of confused on containers though.

  • I tried the container method, but the monster would come in with a health bar and when you shoot it, the health bar goes down which is good. When another instance of that same monster comes in and the first monster isn't destroyed, the second instance wouldn't have a heath bar untill the first one is destroyed. Also, when one instance of the monster is hit once or twice, the next monster will have that same amount of health as the first. Any suggestions on how to fix them?

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