How do I set 1 sprite onto multiple instances of an enemy?

0 favourites
From the Asset Store
Give Sound to the enemies that are part of your game! :)
  • Hey all,

    Im stuck, again

    Im trying to find a way to get a sprite+animation to run on multiple instances of the same enemy. I need the sprite and animation to become visible and run only when each individual enemy is in a collision circle pinned to the player, AND for each instance to have its own sprite+animation running instead of having have ALL enemies in the collision circle for it to work.

    This sounds confusing, so i will provide a screen shot:

    [attachment=0:216eu971][/attachment:216eu971]

    So when each enemy collides with that grey circle pinned to the player, they will each have their own sprite+animation run, but starting with only ONE instance of the sprite+animation which is currently off screen. I hope im making myself clear.

    I have tried using things like "For Each "enemy" with 2 sub events and spawning objects and stuff and i cant get it working >.<

    Thanks in advance for any tips/suggestions,

    If you have any questions, please ask

    moymoymoy

  • Each time the player triggers a collision (the circle around the player) with an enemy, only that enemy's instance should be affected. I don't understand why all of the enemy instances are being triggered.

    Look at this capx and tell me if this is what you want to achieve: http://www.eli0s.com/Tests/ScaredEnemies.capx

    I am using a Boolean Variable on the enemies to check if they have being collided or not and when the Boolean is true, they change their animation and position.

  • Its not allowing me to open that capx because it is from version 167.2 and im on 163 which is the most recent version scirra is allowing me to download?

    I just wanted to clarify though:

    It is a seperate sprite+animation i want to add onto multiple instances of those enemies. Basically, it is an attack animation that will play over their current heads if they are within the circle.

    Appreciate the response, thank you

    Edit: i see it is the beta, i will grab it now

    Edit2: its not quite what im trying to achieve, i hope the clarification above explains myself better

  • So, in essence you would like to spawn an other sprite and change the animation on the current sprite (the enemy) ?

    Download the example capx again, I have updated it to reflect the above requirements.

    And yes, it's the latest beta, sorry, I should have had clarified it

  • Yeah kind of. Id like to spawn another sprite with animation (lets call Sprite1) on the multiple instances of an enemy (lets call this Sprite2).

    I checked the capx and i see the "create object" being used. Is there an option that will allow me to delete the created object if it is not within the collision circle? This would mean that the Sprite1 created would be destroyed but ONLY on an enemy NOT in the circle.

    I will continue to mess around and see if i figure it out but if you could help more, it would be greatly appreciated

  • Ok, so,

    1) You want each enemy instance (Sprite2) to spawn this Sprite1 every time the player's circle collides with the enemy.

    2) You want each Sprite1 (which was created before) to be destroyed if the player's circle is not overlapping the "parent" enemy any more.

    3) You want everything above to be independent from each other, every instance to it's own in relation to the player.

    Considering all the above, this is the best I can think of right now.

    http://www.eli0s.com/Tests/SpawnedIDs.capx

    I am using a distance check instead of the collision polygon of the circle (I've left the circle visible for illustration purposes) and instead of spawning the Sprite1, I set it's opacity to 100 when the player is within the desired distance and to 0 when it's not.

    You can trigger different animations or frame numbers by adding sub-events (if you change the animation, don't forget to add the "Trigger Once While True" under "System" conditions).

    I have to admit, this is more difficult that I'd imagined, correct picking is a #$% and I really don't understand why I had to use the "For Each" loop, since Construct 2 supposedly picks every instance internally by its self.

  • Heya,

    Ive tried an distance check copying your methods on that capx file. See below:

    [attachment=0:11lr0rqc][/attachment:11lr0rqc]

    It gave interesting results. The distance check works perfectly so thank you so so much for that. However, the sprite that spawns (Sprite1) stays stationary and does not move with the enemy. Im thinking of just testing out the pin behaviour and pinning it to an imagepoint. I'll let you know how that goes.

    Thanks a lot for your continued assistance. If there was a way to thumbs up your profile or rate your help, i would give you 10/10

    Edit: Sprite1 in that screenshot is actually called "Sprite5" just to make things more confusing

  • Update: Pin behaviour and "Set position to" did not work.

    This is certainly the most difficult thing ive encountered so far on C2 >.<

  • Update: Together, both the pin behaviour and the "set to position" work lol. The only problem now is getting the sprite to mirror WITH the enemy as it moves along the platform and to be on the correct layer >.<

    One thing after another lol *rolls eyes*

    Thanks again for your help.

  • Hmm, I think you don't use the Pin Behavior correctly. You don't have to pin on some image point, first you set up the position of the child object (the one that has the Pin Behavior) in relation to the parent and then you "fire" the "pin to" action. You can either set the initial position manually in the level editor, or with actions, just like in our example.

    Please, re-download the last example, I've updated it to include the Pin Behavior. I used the Sine Behavior on the Enemy objects just to give some motion and pruve that the spawned object (Sprite1 or 5 or identity crisis ) follows.

    No need for anything, I am glad if I was helpful, by helping others I also learn my self!

    Tell me if everything works ok now

  • Ok, I saw your answer after I posted mine. Glad you figured it out

    As for the mirroring, either use an extra action to mirror the spawned object (Sptrite5) or add both the ForestCow and the Sprite5 in to a family and add the movement and the mirroring to the family object!

  • I should explain further, when the player goes near the enemy, i want a sprite to appear on the enemy. In this case, it is an animated head that tries to bite the player. If the player is not near then the added sprite dissapears and the enemy looks normal again.

    ^^^^^ This we have achieved but without the "set position to" the added sprite stayed in the same place and did not move with the enemy. Without the pin behaviour i had the same thing. With both of them, the added sprite pins to image point 1 (the enemys head) and moves along as the enemy moves left. When the enemy moves right, the added head sprite stays on the position af it was moving left.

    I'll try the Sine behaviour (not used this one before I will update in a few minutes!

  • Ooops just saw your reply too! Sorry hahaha.

    I tried the extra actions for mirroring but it didnt work. Will try the family thing now

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What method do you use to move the enemy? This is important concerning the mirroring. The Sine Behavior doesn't have a condtition to check if you are moving towards the right or left, so I don't think it will help...

    If you like, send me your capx and let me see if I can help directly within your project.

  • I'll add the capx if it would make things easier but here is a screenshot of the movement and attack for the Forest Cow enemy for now:

    [attachment=0:2672vi6k][/attachment:2672vi6k]

    I tried adding in extra actions to mirror the Sprite5 in both parts and with sub events as well and they didnt work.

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