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

1 decade ago by paulh

Hi

Another stupid thing ive forgotten, but how do i set other variables in the settings for a spawned entity?

var settings = {blockType:"X"};
	
	ig.game.spawnEntity(EntitySpawner,200,360, settings);//spawn the game stats


So the above works, but ive tried loads of combinations trying to add the x and y velocity to the settings that i cant get to work :-(

Ideally id like to specify the x, y, vel.x, vel.y, friction.x, friction.y and anything else, but the syntax is avoiding me!


Also is it possible to have a UNIQUE gravity value for a spawned entity?

thx!

1 decade ago by stahlmanDesign

If you are spawning from an entity that has velocity and position etc.:
var settings = 
{"posX":this.pos.x,
"posY":this.pos.y,
"velX":this.vel.x,
"myValue":23,
"gravFactor":0.5}

Then in the spawned entity:
this.pos.x = settings.posX;
this.gravityFactor = settings.gravFactor; // 0.5

1 decade ago by paulh

Thanks

I tried this but get:

Uncaught TypeError: Cannot read property 'x' of undefined

Im spawning the entity from:


	ig.game.spawnEntity(EntitySpawner,220,34, settings);//spawn the game stats


and have


	this.pos.x = settings.vel.x;
	this.pos.y = settings.vel.y;


in my entity init

1 decade ago by paulh

Found it in the documentation, must have looked a hundred times :-)

var settings = {blockType:"X", vel: {x: 110, y: -210}};

just have this in my entity:

EntitySpawner = ig.Entity.extend({
	size: { x:48, y:48 },
	offset: { x:0, y:0 },
	maxVel: {x: 300, y: 1000},
	friction: {x: 150, y: -240},
        blockType: "X",

1 decade ago by auz1111

OK so keep getting the error too:
Uncaught TypeError: Cannot read property 'gamename' of undefined

I've got:

var settings = {gamename:playerlist[i],characterSelectedName:characterSelectedName};
ig.game.spawnEntity( EntityOtherplayer, 160, 260, settings );

EntityOtherplayer = ig.Entity.extend({
		
		
		
		size: {x: 63, y: 95},
	
               type: ig.Entity.TYPE.B,
     
		speed: 100,
		name: "otherplayer",
		gamename: "",
		characterSelectedName: "",
		animation: 1,
        //checkAgainst: ig.Entity.TYPE.B,
		collides: ig.Entity.COLLIDES.PASSIVE,
        
        
		animSheet: new ig.AnimationSheet( 'media/Auz-spritesheet-1.png', 125, 125 ),
	
		init: function( x, y, settings ) {
	     	this.parent( x, y, settings );
		 	this.health = 10;
			//this.gamename = settings.gamename;
			//this.characterSelectedName = settings.characterSelectedName;
			console.log("Game Name: " .  settings.gamename);
			console.log("Character Selected Name: " . this.characterSelectedName);
			


});

When I use the following it doesn't work either...
console.log("Game Name: " .  this.gamename);

1 decade ago by jswart

""Quote from auz1111
OK so keep getting the error too:
Uncaught TypeError: Cannot read property 'gamename' of undefined

I've got:

var settings = {gamename:playerlist[i],characterSelectedName:characterSelectedName};
ig.game.spawnEntity( EntityOtherplayer, 160, 260, settings );

EntityOtherplayer = ig.Entity.extend({
		
		
		
		size: {x: 63, y: 95},
	
               type: ig.Entity.TYPE.B,
     
		speed: 100,
		name: "otherplayer",
		gamename:,
		animation: 1,
        //checkAgainst: ig.Entity.TYPE.B,
		collides: ig.Entity.COLLIDES.PASSIVE,
        
        
		animSheet: new ig.AnimationSheet( 'media/Auz-spritesheet-1.png', 125, 125 ),
	
		init: function( x, y, settings ) {
	     	this.parent( x, y, settings );
		 	this.health = 10;
			//this.gamename = settings.gamename;
			//this.characterSelectedName = settings.characterSelectedName;
			console.log("Game Name: " .  settings.gamename);
			console.log("Character Selected Name: " . this.characterSelectedName);
			


});

When I use the following it doesn't work either...
console.log("Game Name: " .  this.gamename);
""

Here is the docs:

new ig.Entity( x, y, settings )

x, y Position to place this entity in the game world
settings A JavaScript object, whose properties overwrite the entity's default properties
Typically, you should create your entities through the ig.Game's spawnEntity() method, which creates the entity and adds it to the game world.
The settings object overwrites the properties for this one particular entity. E.g.:

var settings = {health: 100, vel: {x: 200, y: 100}};
var myEnt = new EntityMyEntityClass( 0, 0, settings );
Weltmeister makes use of the settings object, to store additional settings for each entity.

If you look in the source code of Impact you will see that anything passed into the 'settings' parameter is merged with 'this', using ig.merg().

Example:

--- main.js ---

ig.game.spawnEntity( EntityPlayer, 200, 200, {'foo':'bar', 'lives':5} );

--- EntityPlayer.js ---

... // entity code

init: function ( x, y, settings ) {
    this.parent( x, y, settings);
    console.log(this.foo); // displays: bar
    console.log(this.lives); // displays: 5
}

You don't need to call:

this.foo = settings.foo; 

because the 'settings' object is being merged with the entity object. So you can simply say:

this.nameOfSettingsProperty

from within the entity.

Hope this helps!

1 decade ago by jswart

Quote from auz1111

EntityOtherplayer = ig.Entity.extend({
		
		// ....
		init: function( x, y, settings ) {
	     	this.parent( x, y, settings );
		 	this.health = 10;
			//this.gamename = settings.gamename;
			//this.characterSelectedName = settings.characterSelectedName;
			console.log("Game Name: " .  settings.gamename);
			console.log("Character Selected Name: " . this.characterSelectedName);
			} // <-- you are missing a closing ' } ' on your init function  


});


Just noticed you are also missing a closing bracket.

1 decade ago by auz1111

@jswart ok I tried that before and it wasn't working... you know why??? I am a bit loopy at 3am...

Check out my console.log... I'm using "." when I should be using "+"... too much php.

I really appreciate your help. I wish there was a way to delete all this, but hopefully it will help the next person who is doing the same, because that was confusing to me.

Thanks bro!

1 decade ago by jswart

Quote from auz1111
@jswart ok I tried that before and it wasn't working... you know why??? I am a bit loopy at 3am...

Check out my console.log... I'm using "." when I should be using "+"... too much php.

I really appreciate your help. I wish there was a way to delete all this, but hopefully it will help the next person who is doing the same, because that was confusing to me.

Thanks bro!


Haha. That is probably why I didn't notice it. I'm a Web App developer... guest what language I use? I'm so used to seeing PHP I didn't notice it as being wrong.

Glad you got it figured out!
Page 1 of 1
« first « previous next › last »