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 AzZzOne

Hi all!

I have an entity in my game which consist of several box2d bodies, i wonder can i apply different animationSheets to each of these bodies? not to the whole entity ?

Thanks!

1 decade ago by Joncom

You might be better off creating each body as a separate entity, but maintain any constraints to one another that they may have. This way, each body can have it's own animation/graphic.

1 decade ago by AzZzOne

Thanks for your answer!

Yes, i thought about this and maybe i'll make each bodies as a separate entity but it seems more complicated right now .. For example i don't understand how to create joints for two separate entities. It's very important for my ropeEntity.

So i'm trying to find another way. Right now i have my body (the rope) drawn by this

 for (i=0;i< this.sections;i++){
	   if (i< this.sections-1) {
	  
	   
	   var posStartX = ig.system.getDrawPos(this.myJoints[i].GetAnchorA().x/Box2D.SCALE-ig.game.screen.x);
	    var posStartY =  ig.system.getDrawPos( this.myJoints[i].GetAnchorA().y /Box2D.SCALE-ig.game.screen.y);
		var posEndX = ig.system.getDrawPos(this.myJoints[i+1].GetAnchorA().x/Box2D.SCALE-ig.game.screen.x);
	    var posEndY =  ig.system.getDrawPos( this.myJoints[i+1].GetAnchorA().y /Box2D.SCALE-ig.game.screen.y);

	     ig.system.context.strokeStyle = "red";
                ig.system.context.lineWidth = 5;
                ig.system.context.beginPath();
                ig.system.context.moveTo( posStartX,posStartY);
                ig.system.context.lineTo(posEndX ,posEndY);
                ig.system.context.closePath();
				  ig.system.context.stroke();
	   }  

I tried to replace it by canvas drawImage() but I did not succeed. I would really appreciate it if someone could tell me how to make it properly if it's possible of course!

1 decade ago by Joncom

You could also create an array of animation sheets, one for each body. Then overload the entity draw method with a loop that goes through the array and draws each animation using the position and angle data for the corresponding body.

1 decade ago by AzZzOne

Hi, Joncom!

Finally i've solved this problem by creating each body as a separate entity like you said. I found this way the most appropriate. It's working very smoothly and there is no problems with weltmeister because you can see there all your entities.
Thanks for your help!

If anyone encounter with this problem i suggest to use this method.
Page 1 of 1
« first « previous next › last »