- Title: LITE Drag and Drop Lighting Tutorial
- Description: Create a simple lighting system in Game Maker 8 Lite using drag and drop only.
- GM Version: GM 8
- Registered: No
- File Type: .gmk
- File Size: 370 KB
- File Link: lighting2.gmk
In this tutorial we are going to create a simple lighting system in Game Maker 8 Lite using drag and drop only. When you are finished, you will have a simple game where the player is an explorer in a dark pyramid with only his torch to guide him. You could also just download the link at the bottom if you don't want to follow the tutorial, but I highly recommend you read this!
Note that before we start, you should be in Advanced Mode (click preferences and make sure Advanced mode is ticked.) To start with, we'll need the sprites for this game. Just download the following gmk:
This game includes all our sprites. These are:
spr_player-a simple sprite of the player with four subimages of four different directions
spr_light-the torch light, with nice alpha effects
spr_mask-a mask of the player for smooth collisions; more on this later
It also has a background entitled bck_sand.
So now we're ready to begin. Let's start by creating an object called obj_player. Set it's sprite to spr_player and it's mask to spr_mask (the mask option can be found underneath the "persistent" check box and the parent option.) Add a create event and put in a change sprite action (found in the main1 tab). The sprite should be spr_player, with a subimage of 0 and a speed of 0. This makes sure that the player's sprite does not spin around insanely. Next, we will make movement. Add a Keyboard, Left action and add a jump to position (move tab) action with an x of -4, a y of 0, and relative checked. Then, add a change sprite action (main1 tab), set the sprite to spr_player, the subimage to 2, and the speed to 0. Let's consideer what this does. First, it jumps to a position 4 pixels to the left. Then, it sets the sprite to the left subimage. Pretty simple, huh? Now, do the same for the up, right, and down events, but they have small differences.
Up should have a x of 0, a y of -4, and a subimage of 1
Down should have a x of 0, a y of 4, and a subimage of 3
Right should have a x of 4, a y of 0, and a subimage of 0
Now that that's all done, we can add a wall object. Give it a sprite of spr_wall and you're done! Yep, that's all you need to do. We can close this up and we won't be using it again throughout the rest of the tutorial.
Next, we need to add collisions. Reopen obj_player and add a collsion event with obj_wall. In it, put the following actions:
jump to position of xprevious and yprevious (move tab)
move to contact with direction: image_index*90 maximum: 4 against: all objects (move tab)
This is a pretty complicated part, but it helps us make smooth collisions. First, when the player collides with the wall, it goes back to it's previous position. Then, it goes in the direction the player is facing until it hits the wall again. This makes sure the player cannot go inside the wall.
Now for the last, and most exciting object: obj_lights. Create it and add a Draw event. Now, we are going to make the lights. The first thing to do is make the torch glow. For this, we will include a draw sprite action. The sprite should be spr_light, the x obj_player.x, and the y obj_player.y. The subimage can be left as -1 or set to 0. Now, we need to make rest of the screen dark.
We will include 4 draw rectangle actions for this. I will not go through these step by step, but here are the values required (they should all have the final property set to filled):
Rectangle 1: 0,0,obj_player.x-64, room_height
Rectangle 2: room_width,0,obj_player.x+64, room_height
Rectangle 3: 0,0,room_width, obj_player.y-64
Rectangle 4: 0,room_height,room_width, room_height, obj_player.x+64
This will draw the darkness around the player. Now, we are done! You can create a test room and put in some walls, obj_player, and IMPORANTLY: obj_light. If you get any errors, feel free to check it against the full version here:
Edited by CaptainLepidus, 16 November 2010 - 02:41 PM.