How do I separate each instance of an object

Get help using Construct 2

Post » Sun Feb 19, 2017 2:10 pm

I wanna create a sprite that will act independently from the other same sprite, with different UID.

I want every sprite moving with and event, but not the same why by their position.

on my project, I have created a sprite named ennemy. This sprite is not ennemy's sprite, is just a sprite for collision an moving. So I created another spriter that I will set every tick on the ennemy sprite.

how can I do an simple event where I will be able to associate, for each instance of an sprite "ennemy" another sprite that are independently moving?
B
9
S
3
Posts: 53
Reputation: 997

Post » Sun Feb 19, 2017 2:17 pm

https://www.noelshack.com/2017-07-1487513711-zezf.jpg

I wanna associate for exemple, this guy with 3 sprite. I want that each sprite are acting independetly. because each sprite will follow a target and they are not in the same position, so they will not act at the same way.

how can I do that?

pic links fixed
Last edited by frayt on Sun Feb 19, 2017 2:54 pm, edited 1 time in total.
B
9
S
3
Posts: 53
Reputation: 997

Post » Sun Feb 19, 2017 2:45 pm

The image link is broken, also my head hurts..
B
45
S
15
G
73
Posts: 2,005
Reputation: 43,392

Post » Sun Feb 19, 2017 2:58 pm

frayt wrote:https://www.noelshack.com/2017-07-1487513711-zezf.jpg

I wanna associate for exemple, this guy with 3 sprite. I want that each sprite are acting independetly. because each sprite will follow a target and they are not in the same position, so they will not act at the same way.

how can I do that?

pic links fixed


You can simply assign their respective functions using the 'Pick Nth instance' you can find under 'System'
Image Image Image
B
29
S
11
G
27
Posts: 729
Reputation: 16,995

Post » Sun Feb 19, 2017 2:59 pm

okay I will explain my project. that's a shooter game. you have player against monsters.

I want that every monsters that appears move to the player to bit him. but the monsters are in a different position on the map. they can move up, left right and down. they will try to reach the player but the problem is that in my eventsheet, every monsters is treated in the same why, even if they get bullet in their head. I want to dissociate each sprite of the instance monster.
B
9
S
3
Posts: 53
Reputation: 997

Post » Sun Feb 19, 2017 3:18 pm

Pick them by using a system 'for each' monster, should treat them separately.
B
45
S
15
G
73
Posts: 2,005
Reputation: 43,392

Post » Sun Feb 19, 2017 3:56 pm

frayt wrote:okay I will explain my project. that's a shooter game. you have player against monsters.

I want that every monsters that appears move to the player to bit him. but the monsters are in a different position on the map. they can move up, left right and down. they will try to reach the player but the problem is that in my eventsheet, every monsters is treated in the same why, even if they get bullet in their head. I want to dissociate each sprite of the instance monster.


First Lets Understand this concept:
Object types are a central part of game design in Construct 2. Object types define a 'class' of an object. For example, TrollEnemy and OgreEnemy could be different object types of the Sprite plugin. They have different animations and events can be applied separately to make them look and act differently, despite the fact they are both Sprite objects.

Then Lets Understand this concept:
Object instances are the actual objects you see in a game: an instance of an object type. For example, if there are four TrollEnemys in a layout, those are four instances of the TrollEnemy object type.

This concept is important:
All instances of an object type use its behaviors. You cannot add a behavior to only some of the instances - they all use the behavior - although you may be able to enable or disable the behavior for individual instances.

Finally This concept may be important:
Containers are an advanced feature to make it easy to build composite objects - that is, elements of your game made from multiple objects. For example, a tank in a strategy game might be composed of two parts: a sprite for the tank base, and a different sprite for the tank turret. This allows them to rotate independently. Adding them both to a container then allows events to treat both objects as if they were one, because they are always picked together.

Example to Complete 3 separate moving sprites with their own behavior.
1. File->New->New Empty Project-> Click Open
2. On the tile layout Tab -> Dbl Click inside the layout and choose Tiled Background -> Click Layout again and add a background image to create your background.
3. The window size of the project, the layout size, and the picture size should all be changed to be the same.
4. The position of the tiled background should be 0,0 as well
5. Find the Layers Tab on the right side and click on it to display the layers of the layout.
6. Rename Layer for the background whatever you want and lock it. Locking it prevents messing it up as you develop.
Background should be ready
Add a new layer
1. Click the "plus" sign. Add a new layer and rename it to something like "Main"
2. Make sure you remain in the layer that you create and rename to "main" or whatever you named it. We want to add the sprites to this layer. Not the background Layer.
3 Double click on the layout screen ->insert new object-> Sprite -> Click on layout screen again and Add the sprite
4. Name you sprite something like "Luke"
5. Add a behavior to Luke by using the behaviors link on left side. Add a behavior like "Fade"

Test the game. We should now have 1 sprite named Luke who fades away.
1. Now repeat that process naming a new sprite as "Jeb" and assigning him a different behavior like "Bullet"
Important: You do not create a new "instance" of Luke using the Ctl Drag method. This just creates another "Luke"
2. You will need to click on the Layout and add another actual sprite.
Got it?

Under the layers Tab you should have 3 objects listed. Luke, Jeb, and a tiled background
When you Play the game they should operate independent from each other.

Bonus Idea. Containers.
1. Click on the sprite "Luke" . In same area you added a behavior to "Luke" look for Container and choose Create
2. Choose the Other sprite you created and this will group both sprites into a Container that allows them to have independent behaviors and yet be grouped together.

Hope this help. Let me know if anything is unclear or needs reworded.
B
17
S
7
G
8
Posts: 18
Reputation: 4,870

Post » Sun Feb 19, 2017 5:56 pm

@frayt

Give the Monster an instance variable called Alive that is true initially that you set to false when "they get bullet in their head" or are otherwise killed.

Then do:
Code: Select all
for each Monster
   Monster.Alive = true
      Player.X < Monster.X: Monster move left
      Player.X > Monster.X: Monster move right
      Player.Y < Monster.Y: Monster move up
      Player.Y > Monster.Y: Monster move down


This should move only living Monsters towards the player, with each Monster moving independently.
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
32
S
9
G
7
Posts: 444
Reputation: 6,731


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], JarkeyBacon and 4 guests