# how to respawn Enemies and Targets

**URL:** https://forum.kirupa.com/t/how-to-respawn-enemies-and-targets/658171
**Category:** web dev
**Created:** [April 13, 2023, 10:30pm UTC](https://forum.kirupa.com/t/how-to-respawn-enemies-and-targets/658171 "2023-04-13T22:30:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AmiiboAmigos](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/amiiboamigos/32/19755_2.png) [@AmiiboAmigos](https://forum.kirupa.com/u/AmiiboAmigos)
#### Post date: [April 13, 2023, 10:30pm UTC](https://forum.kirupa.com/t/how-to-respawn-enemies-and-targets/658171/1 "2023-04-13T22:30:46Z")

</div>

I’m almost done! all I need to do is to add code to respawn enemies and targets to this game in JavaScript.  
Anyone have any ideas? there aren’t many sources with the kind of code I’m looking for.

Replit: [Join AnaeliRivera's "EnemyGame " - Replit](https://replit.com/join/mtpjewluiy-anaelirivera)

---

<div class="post-metadata">

### Author: ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)
#### Post date: [April 14, 2023, 12:13am UTC](https://forum.kirupa.com/t/how-to-respawn-enemies-and-targets/658171/2 "2023-04-14T00:13:59Z")

</div>

One of the best YT channels for JS game dev is  
[https://www.youtube.com/@Frankslaboratory](https://www.youtube.com/@Frankslaboratory)

check out [Performance optimisations](https://www.youtube.com/watch?v=NYzvdfkDOU4)  
and [State mangement](https://www.youtube.com/watch?v=jKe44NeFzwE&t=142s)

I’ve used both finite state machines and the object pool method for a few projects and the performance is great…

---

<div class="post-metadata">

### Author: ![AmiiboAmigos](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/amiiboamigos/32/19755_2.png) [@AmiiboAmigos](https://forum.kirupa.com/u/AmiiboAmigos)
#### Post date: [April 19, 2023, 5:32pm UTC](https://forum.kirupa.com/t/how-to-respawn-enemies-and-targets/658171/3 "2023-04-19T17:32:42Z")

</div>

Hmmm, I have seen his videos; they did help. however not for this particular instance.  
But I do want some thoughts on how I should go about this.

Should I refresh the whole page seconds after defeating the last enemy or should I have an enemy spawn right after one is deleted?

I’m asking because I already have this code:

```auto
setInterval(()={
  window.location.reload()
},2000) // Reload after 2 seconds

```

Of course, I can just go the easy way and just refresh the page in 2 seconds.

Or the more practical but difficult way.

What are your thoughts and advise if any?
