Simple Custom Movement Tutorial by Nivram

Beginner-Should have a basic understanding of MMF.

You will learn the following:
How to make a Character move with a simple custom movement.

We will be doing an Simple Custom Movement Tutorial. There will be no extensions required, but you should download the .mfa file so you can follow along, or compare my .mfa file to the one you will be building.

simplecustommovementtutorial.mfa (35kb)

This will be a non-scrolling Application using an active character with "Static Movement". Static means we will not be assigning any kind of movement, and this is the default movement for MMF when you first create an active object.

Open up MMF and click New under File. Rename your Application to Simple Custom Movement. Save as CustomMovement2. I would like to comment that you should save any project you are building often.

Create an Active Object 32X32 and place the Hot Spot to the center. Rename it Character. Place the Character in the Frame. The color you make it does not matter and do not assign any movement. Save your Application.

In the Events Editor and for your first code make a Comment:
Simple Custom Movement Example by "your name".

Make a Group Event and name it:

Movement Set Up

Leave the "Active when frame starts" checked.

Let's make four other Group Events:

Move Right
Move Left
Move Up
Move Down

Uncheck "Active when frame starts"

Movement Setup Group Events

Add these events to the Movement Setup Group Events. They are going to be activating and deactivating the different Move Group Events.

Upon pressing Right Arrow
Activate Group Move Right
Deactivate Group Move Left
Deactivate Group Move Up
Deactivate Group Move Down
Character: Toggle internal flag 1
Set internal flag 2 off
Set internal flag 3 off
Set internal flag 4 off

Upon pressing Left Arrow
Activate Group Move Left
Deactivate Group Move Right
Deactivate Group Move Up
Deactivate Group Move Down
Character: Toggle internal flag 2
Set internal flag 1 off
Set internal flag 3 off
Set internal flag 4 off

Upon pressing Up Arrow
Activate Group Move Up
Deactivate Group Move Right
Deactivate Group Move Left
Deactivate Group Move Down
Character: Toggle internal flag 3
Set internal flag 1 off
Set internal flag 2 off
Set internal flag 4 off

Upon pressing Down Arrow
Activate Group Move Down
Deactivate Group Move Right
Deactivate Group Move Left
Deactivate Group Move Up
Character: Toggle internal flag 4
Set internal flag 1 off
Set internal flag 2 off
Set internal flag 3 off

We toggle the flag so that if the user presses the Right Arrow Key again it stops the character by turning Flag 1 off.The reason we are deactivating unneeded groups and flags is so that the character doesn't get confused, and move in only one direction at a time.

Save your Application.

Move Right Group Events

The first event in the Move Right Group Events will tell the Character if my Flag 1 is on, move me 1 pixel to the right. If my Flag 1 is off, stop me from moving:

Character internal flag 1 is on
Character: Set X position to X ("character")+1

The next event will be an expansion event so that if you want to add to your application, the event will be in place. It backs the character out of an obstacle and sets Flag 1 off:

Character overlapping obstacle
Character: Set X position to X ("character")-1
Turn internal flag 1 off

You don't want your character to walk off the screen, so add this event:

Character is getting closer than 5 pixels from Window's edge
Character: Set X position to X ("character")-1
Turn internal flag 1 off

A word of warning here. If you use an animated character it may become stuck if it turns, as this will place it inside an obstacle or closer than 5 pixels from the edge of your screen. All you need to do is Always set your animated character to the current active you are using for movement, and at the Start of the frame set your current movable active to invisible.

This event tells the program, if the characters internal flag 1 is off, deactivate Group Event Move Right:

Character internal flag 1 is off
Deactivate group "move right"

This is all the events for Move Right Group Events

Save your application and test it. Your character should start moving right when you press the Right Arrow Key and stop when you press it again.

Move Left Group Events

We will add the events to the Move Left Group Events and they will have your character move to the left.

Character internal flag 2 is on
Character: Set X position to X ("character")-1

The next event will be an expansion event so that if you want to add to your application, the event will be in place. It backs the character out of an obstacle and sets Flag 2 off:

Character overlapping obstacle
Character: Set X position to X ("character")+1
Turn internal flag 2 off

You don't want your character to walk off the screen, so add this event:

Character is getting closer than 5 pixels from Window's edge
Character: Set X position to X ("character")+1
Turn internal flag 2 off

This event tells the program, if the characters internal flag 2 is off, deactivate Move Left Group Events:

Character internal flag 2 is off
Deactivate group "move left"

This is all the events for Move Left Group Events.

Save your application and test it. Your character should start moving left when you press the Left Arrow Key and stop when you press it again.

Move Up Group Events

We will add the events to the Move Up Group Events and they will have your character move to the up.

Character internal flag 3 is on
Character: Set Y position to Y ("character")-1

The next event will be an expansion event so that if you want to add to your application, the event will be in place. It backs the character out of an obstacle and sets Flag 3 off:

Character overlapping obstacle
Character: Set Y position to Y ("character")+1
Turn internal flag 3 off

You don't want your character to walk off the screen, so add this event:

Character is getting closer than 5 pixels from Window's edge
Character: Set Y position to Y ("character")+1
Turn internal flag 3 off

This event tells the program, if the characters internal flag 3 is off, deactivate Move Up Group Events:

Character internal flag 3 is off
Deactivate group "move up"

This is all the events for Move Up Group Events.

Save your application and test it. Your character should start moving up when you press the Up Arrow Key and stop when you press it again.

Move Down Group Events

We will add the events to the Move Down Group Events and they will have your character move to the down.

Character internal flag 4 is on
Character: Set Y position to Y ("character")+1

The next event will be an expansion event so that if you want to add to your application, the event will be in place. It backs the character out of an obstacle and sets Flag 4 off:

Character overlapping obstacle
Character: Set Y position to Y ("character")-1
Turn internal flag 4 off

You don't want your character to walk off the screen, so add this event:

Character is getting closer than 5 pixels from Window's edge
Character: Set Y position to Y ("character")-1
Turn internal flag 4 off

This event tells the program, if the characters internal flag 4 is off, deactivate Move Down Group Events:

Character internal flag 4 is off
Deactivate group "move down"

This is all the events for Move Down Group Events.

Save your application and test it. Your character should start moving down when you press the Down Arrow Key and stop when you press it again.

We should be done with our simple custom movement. Your Character should be able to move in four directions.

© 2008-2012 Marvin Hull