

#Gamemaker 1.4 tutorial code
Now we are ready to pass our code from the parent to the new object, which will be referred to as the child object from here on out.Ĭhild object create event event_inherited() Ĭhild object step event event_inherited() īy calling the event_inherited function, the code from the parent object is passed down. Assign a sprite to this new enemy object, and set the parent to parentEnemy.įinally, add the create event, step event, and draw event. Create a sprite of some kind for your new enemy, it doesn’t matter what it looks like, and then create a new enemy object. Now we need to create an enemy object to pass this code to.

In this case, we are just going to destroy the object. Life is the amount of health/hp our enemy will have, and dead is a boolean that lets us define what happens when the enemy’s life reaches zero.

In the create event we are initializing two variables. Add the create event and step event, and let's add some code. This object does not need to have a sprite. Create a new object and name it parentEnemy. This object will not need to exist in the actual game itself, because it will only be passing its code to objects that will exist in the game. The first thing we need to do is create the actual parent object. This is exactly what we will be doing in this example. You can save a lot of time by creating a parent enemy object, which has common variables and code that all of your enemies may need, and passing it down. A parent object is able to pass its code down to child objects, which then run the parent code as if it were their own. Howdy folks! It’s me again, back with yet another GameMaker basics tutorial, this time about parenting and inheritance.
