Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

6 years ago by SlinkyDinky

So I wanna spawn an enemy randomly from the beginning of the game, but apparently there's no way to do so, without an instance already created by Weltmeister, or is there?

Also: How do I make sure that the spawning point for the new enemy is free of both player and other enemies?

6 years ago by end3r

There is spawnEntity method which will spawn your enemy without the need to have him placed in the Weltmeister editor. You just need to have the enemy entity defined in the code. It can be placed randomly, just put a random numbers for X and Y.

I think the checkAgainst method should work to see if the enemy is overlapping with player or other enemy, so you'll place new entity only when it's not colliding.

6 years ago by SlinkyDinky

There is spawnEntity method which will spawn your enemy without the need to have him placed in the Weltmeister editor. You just need to have the enemy entity defined in the code. It can be placed randomly, just put a random numbers for X and Y.

Then I must be doing it wrong because my code only works if an enemy entity is already placed via Weltmeister.
I start out by creating a timer in the MyGame constructor:

spawnTimer: new ig.Timer(),

Then, during my update method I check the spawnTimer, and spawns enemies if 2 seconds have passed:

		if(this.spawnTimer.delta() > 2){
			ig.game.spawnEntity(EntityEnemy, [x-value], [y-value]);
			this.spawnTimer.reset();
		}

The x and y-values are obviously placholder in the above example. My own code places them within the correct borders.
As I wrote: It works, but only if I've already placed an enemy entity within Weltmeister.

I think the checkAgainst method should work to see if the enemy is overlapping with player or other enemy, so you'll place new entity only when it's not colliding.

I'll give it a shot, thanks.

6 years ago by end3r

You have to either define your entity in the main file (outside of the MyGame) like so: myEntity = ig.Entity.extend({ ... }); or if it's defined in another file just add it to the requires section: 'entities.myEntity'. Then you can spawn it whenever you want with spawnEntity(myEntity, x, y);.

6 years ago by SlinkyDinky

(...) or if it's defined in another file just add it to the requires section: 'entities.myEntity'. Then you can spawn it whenever you want with spawnEntity(myEntity, x, y);.

Ah, of course! Forgot about that, thanks.
Page 1 of 1
« first « previous next › last »