0 Favourites

How do I set a sprite position to an enemy box

  • 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?

  • 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..

  • 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.

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • The container did the trick. Shall I be avoiding it?

  • No the container should be fine, if it works for what you need

  • 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?

  • 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

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

    [quote:1ljtkw7l]

    Every tick

    For Each EnemyBox

    Pick EnemySkin.Enemybox_UID = EnemyBox.UID

    ---> Set Enemyskin.X/Y = Enemybox.X/Y

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

    [quote:2iyu6zao]

    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.

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