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 Harley

Hello,

I have an inheritance structure setup like this...

ig.Entity ->
EntityLevel ->
EntityLevel1
EntityLevel2

In the EntityLevel I have a 'this.levelStarted' set to false. I also have a method called 'startLevel' which sets this.levelStarted to true and then the update and draw functions will run.

I then overwrite startLevel in EntityLevel1 to add some more behaviour and call 'this.parent' at the end to ensure that the 'this.levelStarted' will be set to true (among other things).

And it is setting it to true with no issues. However it seems to be ignoring the update and draw methods of the parent, because those aren't being run at all.

Thanks for your help and hopefully that made sense.

1 decade ago by quidmonkey

Is EntityLevel1 = EntityLevel.extend? Post some sample code.

1 decade ago by Harley

Sample code is a good idea....

EntityLevel = ig.Entity.extend(
{
       levelStarted: false,

       init: function(x, y, settings) 
       {
	        this.parent(x, y, settings);
       },

       update: function() 
       {
            if (this.levelStarted)
	        {
                 // do stuff
                 // if I call startLevel from sub class this isn't being reached at the moment.
            }
       },

       draw: function() 
       {
            if (this.levelStarted)
	        {
                // do stuff
                // if I call startLevel from sub class this isn't being reached at the moment.
            }
       },

       startLevel: function()
       {
            this.levelStarted = true;
       }
});

And the sub class:

EntityLevel1 = EntityLevel.extend(
{
    init: function(x, y, settings)
	{
		this.parent(x, y, settings);
	},

    startLevel: function()
	{
         // do some stuff first
        this.parent();
         // if I alert(this.levelStarted) from here, it says it's true.
	}
});

1 decade ago by jswart

Level1 = Level.extend(

//...

I'm pretty sure this is the issue. Like quidmonkey said you should have:


EntityLevel1 = EntityLevel.extend(


If I remember correctly when you work with entities, you need to prepend 'Entity' to "class" names.

1 decade ago by Harley

I added the "Entity" to the front of the class names and it made no difference. I thought that requirement was only there if you were going to use the entity in Weltmeister? These entities are just being called manually.

(I updated the code above with the new class names).

1 decade ago by jswart

Maybe if you post the code where you are actually 'instantiating' these objects and calling the child class object's 'startLevel()' method more people will be able to help.

From what I see, it looks like it should work. So something else must be the issue.

When you run the game with the developer console up do you get any errors? No such thing as too much information when bug hunting.

1 decade ago by Heiko

Agree with jswart. From what I can see I would also expect code to work. Thus need more info/code.

Only thing I can think of is that maybe if you override the update and draw functions in your inherited classes (EntityLevel1 and EntityLevel2), you not calling the base function ?

1 decade ago by Harley

I tracked it down in the end. In the subclass when I was calling this:

startLevel: function()
    {
         // do some stuff first
        this.parent();
         // if I alert(this.levelStarted) from here, it says it's true.
    }

The comments where it says "do some stuff first" - I was loading an impact level here. I have no idea why this wasn't playing nicely with the inheritance though.

In the end I fixed it by pulling all of the startLevel code out and putting it into the init() function but with a settings flag to start it or not. For some reason the loadLevel call didn't seem to interfere with the inheritance when it was in the init function.

1 decade ago by Harley

I tracked it down in the end. In the subclass when I was calling this:

startLevel: function()
    {
         // do some stuff first
        this.parent();
         // if I alert(this.levelStarted) from here, it says it's true.
    }

The comments where it says "do some stuff first" - I was loading an impact level here. I have no idea why this wasn't playing nicely with the inheritance though.

In the end I fixed it by pulling all of the startLevel code out and putting it into the init() function but with a settings flag to start it or not. For some reason the loadLevel call didn't seem to interfere with the inheritance when it was in the init function.
Page 1 of 1
« first « previous next › last »