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 stahlmanDesign

If I extend EntityPlayer to create a few different versions like EntityPlayerFlying, EntityPlayerSwimming, and later I do this:
var player = this.getEntitiesByType(EntityPlayer)[0];

will it recognize my extended classes as also being the one they inherit from? This works in other languages but I don't know about JavaScript. I'll probably do a test if no one knows.

1 decade ago by fugufish

if you do that, you will get the first entity in EntityPlayer

e.g, if you put 5 EntityPlayers in your level, only the first will be called

if you do


this.getEntitiesByType(EntityPlayerFlying)[0];


yep you'll get the exactly that.

just make sure that in your player-flying.js, you require 'game.entities.player'


ig.module(
	'game.entities.player-flying'
)
.requires(
	'game.entities.player'
)
.defines(function(){
    EntityPlayerFlying = EntityPlayer.extend({
        // code here
    });
});

1 decade ago by stahlmanDesign

Yeah I knew that was a bad example because there would no longer just be one EntityPlayer floating around. But it looks like you've answered the question that it would work.
Page 1 of 1
« first « previous next › last »