# Spawning multiple enemy types

**URL:** <https://forum.defold.com/t/spawning-multiple-enemy-types/7861>\
**Category:** Questions\
**Created:** [April 27, 2017, 3:46pm UTC](https://forum.defold.com/t/spawning-multiple-enemy-types/7861 "2017-04-27T15:46:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomires](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/tomires/32/3885_2.png) [@Tomires](https://forum.defold.com/u/Tomires)\
**Post date:** [April 27, 2017, 3:46pm UTC](https://forum.defold.com/t/spawning-multiple-enemy-types/7861/1 "2017-04-27T15:46:47Z")

</div>

Hello,

I am looking for a straight-forward way to generate multiple instances of an enemy (in my case, three kinds of bunnies - white, black and brown).

If I understand correctly, I cannot change atlas used within the sprite component of a game object on runtime. Do I have to create one game object and one associated factory per enemy type or is there a better way (that doesn’t involve lumping all frames of animation for all enemies into one atlas)?

---

<div class="post-metadata">

**Author:** ![andreas.strangequest](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/andreas.strangequest/32/3622_2.png) [@andreas.strangequest](https://forum.defold.com/u/andreas.strangequest)\
**Post date:** [April 27, 2017, 5:07pm UTC](https://forum.defold.com/t/spawning-multiple-enemy-types/7861/2 "2017-04-27T17:07:46Z")

</div>

If you for reasons cannot bundle all images in one atlas (which is always preferrable if you can as you will possibly lower the amount of drawcalls ) you can either:

1. Do what you proposed and create a new gameobject, new factory etc. This is not so fun if you have the same logic in the scripts etc and just want to adjust properties in the script for different behaviour

2. Create several sprites (with different atlases) within a gameobject and disable/enable them as you are passing in a “type” go.property into the factory.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 27, 2017, 8:29pm UTC](https://forum.defold.com/t/spawning-multiple-enemy-types/7861/3 "2017-04-27T20:29:25Z")

</div>

> [@Tomires](#):
>
> that doesn’t involve lumping all frames of animation for all enemies into one atlas

Because the atlas becomes to large or because you will never have all enemies active on a level at the same time? If it’s not one of these reasons then I’d suggest that you reconsider and put all animations in a single atlas since that will be way more efficient to render

---

<div class="post-metadata">

**Author:** ![Tomires](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/tomires/32/3885_2.png) [@Tomires](https://forum.defold.com/u/Tomires)\
**Post date:** [April 27, 2017, 8:41pm UTC](https://forum.defold.com/t/spawning-multiple-enemy-types/7861/4 "2017-04-27T20:41:08Z")

</div>

Mainly because of concerns about the size of the atlas. Right now the atlas for each enemy is 2048x1024 in size. The number of animations is quite large.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 27, 2017, 9:18pm UTC](https://forum.defold.com/t/spawning-multiple-enemy-types/7861/5 "2017-04-27T21:18:34Z")

</div>

Ah, I see. Well, then you’re unfortunately not able to simply change the animation on the sprite. I guess the options provided by Andreas are the ones to look into. Or maybe switch to spine animations instead of flip book if that helps.

---

<div class="post-metadata">

**Author:** ![Tomires](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/tomires/32/3885_2.png) [@Tomires](https://forum.defold.com/u/Tomires)\
**Post date:** [April 27, 2017, 9:32pm UTC](https://forum.defold.com/t/spawning-multiple-enemy-types/7861/6 "2017-04-27T21:32:54Z")

</div>

I will be going with the second option provided by Andreas. We have tried integrating Spine into our workflow and found out it is pretty tricky to animate characters in isometric perspective.
