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 Mario

Hi iam new with Impact and want to share my solution:

i was stuck in moving an entity as parent... so it moves it childs as well.

so i had changed the entity.js (sure it could be a plugin :) )

please see below

so you can move your parent with moveBy(deltaX, deltaY);

i hope someone need this as well :)

1 decade ago by Mario

hello, i found some errors and make some process with the plugin.

ps: is there a way to edit my first post?

ig.module(
    'plugins.entitychilds'
).requires(
    'impact.entity'
).defines(function() {
  ig.Entity.inject({
	// array of child entities
	childs: new Array(),
	
	//override
	update: function() {
		this.parent();
		for(var i=0; i<this.childs.length; i++) {
			this.childs[i].update();
		}
	},
	//override
	draw: function() {
		this.parent();
		for(var i=0; i<this.childs.length; i++) {
			if( this.childs[i].currentAnim ) {
				this.childs[i].draw();
			}
		}
	},
	//override
	kill: function() {
		this.parent();
		while(this.childs.length>0) {
			this.childs[0].kill();
			this.childs.erase(this.childs[0]);
		}
	},
	//override
	receiveDamage: function( amount, from ) {
		this.parent( amount, from );
		for(var i=0; i<this.childs.length; i++) {
			this.childs[i].receiveDamage(amount, from);
			if( this.health <= 0 ) {
				this.childs.erase(this.childs[i]);
				i--;
			}
		}
	},
	addChilds: function( newChilds ) {
		for(var i=0; i<newChilds.length; i++) {
			this.childs.push(newChilds[i]);
		}
	},
	removeChilds: function( delChilds ) {
		while(delChilds.length>0) {
			this.childs.erase(delChilds[0]);
		}
	},
	moveBy: function( x, y ) {
		this.pos.x += x;
		this.pos.y += y;
		for(var i=0; i<this.childs.length; i++) {
			this.childs[i].moveBy(x, y);
		}
	},
});
})

1 decade ago by clok

This is cool @Mario. I will have to try this out.

To edit old post, just highlight the title of the post and on the right side there should be an "edit" option next to quote if you are logged in and are the owner of the post.

EDIT: You should post this plugin on Point Of Impact

1 decade ago by Mario

thx for your answer.

i dont have to deal with kill and damage at my current project so this part is not tested jet... and after someone or i tested this i will post it on POI
Page 1 of 1
« first « previous next › last »