Game maker solid gml
When actions or code is placed in a collision event for a solid object, the two objects cannot overlap. So if you have non- solid objPlayer , and solid objBlock , and you add a collision event in objPlayer for objBlock , then whenever objPlayer bumps into objBlock it will be kicked back to the last hopefully non-colliding position.
Same thing with the block; if it happened to be moving and the player was stationary, the block still could not enter the player. Well, if your object is moving and touches a solid object, it will be moved out of it. Actually, that is the very reason why you should get rid of it.
What if at one point you want the object to go through walls? What are you to do? If you turn solid off, all you have to do to keep a functional game is to program the collisions yourself. Take the more difficult path and collect the treasure at the end. Now, you can include conditionals, etc. For a top-down maze game, you might use this code in the step event:. One last thing that I feel I should mention.
If a position is collision free. Action form:. If there is an object at a position. But that means, if you have 15 different wall objects you have to use this function 15 different times, right? Um, no. When have I ever steered you down such an annoying path? In fact, with a little creativity, you only have to use it once. The way you do this, is to make a new object, and call it objBlockParent. You guessed it, this object will in fact be a dummy object with no code of its own, only to be used as the parent object of all block objects.
The code example above could replace objBlock1 with objBlockParent and work in just this way. Now that you have turned off solid , you can even make things like one-way platforms. But be sure to remember this for future games. To discuss this article in particular, you can view it on the Game Maker Community. Enter your email address to subscribe to the SoulScroll and be notified by email right when a new article is posted.
Email Address:. I want to subscribe! For this inventory I am going to use an array to store all the data in. We must first decide what data this is. In our case we will store the following data:. To store this data I am going to use a 2D array. Every item will receive a number. Within a 2D array you can now store for every item several things. All this information must be declared at the start of the game.
This will go like:. Now you have declared the lives item in your inventory. Please note that All information is stored in a global variable so every object can read this data at any time.
In my case I gave every piece of info it's own number. For instance the sprite has received number 2. Also the item lives has received number 0. If you now want to declare the sword item you change the 0 after global. You can call the sword for instance 1. Then declaring the sword will go:. Now you can use the same code for all the other items as well. You then get a long script in which every single specification is declared for every item.
Place this script in the Game Start event. The last item in the list of declarations is the code to execute when the item is selected. You could execute a script at that time or change a variable. This tutorial does not descripe how to do this. You now need to draw the inventory system.
In this tutorial I will explain how to do it in a special room for the inventory where everything is stored. To draw the inventory a special object is used that is only placed in that room. To make the inventory look nicely I will take the following sizes:. Since the room is width we can place the inventory completely on one line and draw in the rest of the screen the description of the items.
If we have 5 items we have 6 empty spaces between the items. Now lets start with the drawing code. We need to draw the items one by one on the screen. We have five items. So first we need to have a loop that draws the sprites of all the objects Of cource the drawing code goes in the drawing event :.
This code will draw the five inventory images on the screen on the top line as the screenshot shows.
0コメント