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 ansimuz

Hi

I want to override a function defined in a parent entity. How can i do this.

The parent has this:

handleMovementTrace: function(res){
                this.parent(res);
                // wall collision
                if(res.collision.x){
                    this.flip = !this.flip;
                }
            },

I want the child entity to behave different. For example i dont want it to have a wall collision return.

handleMovementTrace: function(res){
            // remove wall collision
            this.parent(res);
            if(res.collision.x){
                this.flip = this.flip;
            } 
        }

Hope it makes sense.

1 decade ago by mLautz

There are a couple points here. If you want to remove the parent functionality, simply override the function and do not call to:
this.parent(res);

If you want to maintain part of the parent functionality, but not the rest. Then you have a different issue.

1 decade ago by ansimuz

Thanks mLautz.

But if i remove the this.parent(res) i lose the movement for my entity.

Its there a way to call the parent's parent so i can skip the parent logic?

1 decade ago by mLautz

I haven't tried it, but you may be able to directly access in a manner similar to
ig.Entity.handleMovementTrace

In which case you could assign your movement trace to be that function. In theory.

1 decade ago by quidmonkey

You can call a prototype's method like so:
ig.Entity.prototype.handleMovementTrace(res);

1 decade ago by mLautz

Thanks quid! I felt like there was a better way out there, but I didn't know it yet.
Page 1 of 1
« first « previous next › last »