How do I set a sprite position to an enemy box

Get help using Construct 2

Post » Sat Aug 08, 2015 10:31 am

Hello. So I guess this is a basic stuff but somehow can't manage to make it work.

I have a player box and a player skin set to player box on every tick. This works great for my player but when it comes to enemies, since they're clone of eachothe, the set position only works for the very first enemybox and the other ones remain invisible since they have no skin attached.

How can I attach a skin to an enemy box so it shows up in every enemybox clone?
B
14
S
5
Posts: 248
Reputation: 1,705

Post » Sat Aug 08, 2015 10:48 am

Easiest way would probably be putting the enemy-box and the enemy animation in a container and having them created together, so they always reference eachother.

Another way would be to pick the nearest enemy box and have the enemy set an instance variable to it's uid..
then if the instance variable is the same as enemybox.uid set the position..

Instead of setting position every tick you could ofcourse also use the pin behaviour..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Aug 08, 2015 12:55 pm

LittleStain wrote:Easiest way would probably be putting the enemy-box and the enemy animation in a container and having them created together, so they always reference eachother.

Another way would be to pick the nearest enemy box and have the enemy set an instance variable to it's uid..
then if the instance variable is the same as enemybox.uid set the position..

Instead of setting position every tick you could ofcourse also use the pin behaviour..


I tried the pin behaviour before for the player, that was the way I had set it up but it was giving me some problems the more I advanced further.

Just tried the container. All I had to do is add them in a container and voilá. Hopefully it won't cause me any trouble.
B
14
S
5
Posts: 248
Reputation: 1,705

Post » Sat Aug 08, 2015 1:09 pm

Smileh wrote:Hello. So I guess this is a basic stuff but somehow can't manage to make it work.

I have a player box and a player skin set to player box on every tick. This works great for my player but when it comes to enemies, since they're clone of eachothe, the set position only works for the very first enemybox and the other ones remain invisible since they have no skin attached.

How can I attach a skin to an enemy box so it shows up in every enemybox clone?


If I understand what you are trying to do to. You can do it like this.
Since you always have an EnemyBox and a Skin for each enemy. You make a variable in you Skin object called "Enemy_UID" and here you store the Enemybox.UID.

Every tick
For Each EnemyBox
Pick EnemySkin.Enemybox_UID = EnemyBox.UID
---> Set Enemyskin.X/Y = Enemybox.X/Y

However the Pin behaviour should be able to do the same, using a similar setup, you just have to be aware that if you need to pin more objects together than 2 you always have to pin to the same main object or you will get "ghost trails" or what to call it.

So:
Pin -> Main <- Pin (That's fine)
Main <- Pin <- Pin (Last object create ghost trails)

However this might be true for every tick positioning as well. I cant remember. But anyway only important if you pin more than 2 objects together.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sat Aug 08, 2015 1:27 pm

The container did the trick. Shall I be avoiding it?
B
14
S
5
Posts: 248
Reputation: 1,705

Post » Sat Aug 08, 2015 1:42 pm

No the container should be fine, if it works for what you need :)
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Wed Dec 23, 2015 7:45 am

@nimos100 By container, do we mean Family? Do you usually put all the hit detect and health on the enemy box and the only thing the enemy sprite does is do the visual part?
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
55
S
18
G
2
Posts: 436
Reputation: 5,607

Post » Wed Dec 23, 2015 8:44 pm

jook00 wrote:@nimos100 By container, do we mean Family? Do you usually put all the hit detect and health on the enemy box and the only thing the enemy sprite does is do the visual part?

Not sure I understand your question, I was answering the OP regarding what he was trying to get help with. But guess your question is whether I would make a "hit box" and then attached a skin to it, only for the visual part? if that's the case, then I wouldn't use that approach, at least my first thought is that there are no benefits in doing it like that, or at least I can't think of a situation where I would find this to be needed. The reason is that you will end up using more objects than necessary, which will consume primarily memory if these are sprites.

Besides that I would store all the variables in either a family or the sprite it self and simply adjust the collision mesh if I were unhappy with it.

But again I weren't sure what the OP was working on, so it might have been needed for him. And my comment on the container was just, that he said it worked for him. And if that were the case then I guess he was happy :D
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Wed Dec 23, 2015 9:43 pm

@nimos100 Actually, what you mentioned above worked for my issue. Thanks!

Every tick
For Each EnemyBox
Pick EnemySkin.Enemybox_UID = EnemyBox.UID
---> Set Enemyskin.X/Y = Enemybox.X/Y
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
55
S
18
G
2
Posts: 436
Reputation: 5,607

Post » Wed Dec 23, 2015 10:49 pm

jook00 wrote:@nimos100 Actually, what you mentioned above worked for my issue. Thanks!

Every tick
For Each EnemyBox
Pick EnemySkin.Enemybox_UID = EnemyBox.UID
---> Set Enemyskin.X/Y = Enemybox.X/Y

I see, that's good :)

Well this method I use a lot, its good for linking things together. For instant if a unit is killed and depending on which unit it is, something else only related to this unit should also be removed. So storing the UID of the child in the parent object works very well for something like this, when the objects are not in a container.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848


Return to How do I....?

Who is online

Users browsing this forum: vutankhoa2015 and 22 guests