Tutorial: Pixel Based Tile Collisions
Difficulty: Advanced
RPG Maker: 2000/2003
Author: Solitary Angel

The name of the tutorial doesn't exactly do it justice, it is a means of being able to have objects such as pictures moving at different speeds collide with tiles, not only that, but it allows these objects to collide with certain parts of a tile.

The equation of it is fairly simple, it's merely a matter of finding a use for it.
Coding complex systems such as platformers benefit greatly from this so it is a very important thing to learn before attempting anything like that.

So let's go about this then, the first thing you'll need is a couple of tracker variables, generally speaking if you're using free moving pictures, your tracker variables are usually something like 'Picture X' and 'Picture Y'.
To get a basic test system working, make a map event, set these 2 variables to any number you wish, open a loop, then add 1 to one of them every 0.1 seconds.
From here, let's set up 2 more variables, we'll call them 'Picture Tile X' and 'Picture Tile Y', these will go within the loop.
Set 'Picture Tile X' to 'Picture X' and 'Picture Tile Y' to 'Picture Y', you'll want to do this after you've added 1 to that other variable and before the wait occurs.

From here it's simple, multiply 'Picture Tile X' and 'Picture Tile Y' by 100, then divide them by 16.

tilecol1

Now you can already imagine that we're going to have a fairly big number come out of this, but it's how it works.
Test it out for yourself, check your debug menu frequently and watch what happens.

tilecol2

Here are our base statistics, what do you notice?
If the Picture is at the X coordinate of 160, the Tile X coordinate is 1000, shouldn't it be smaller?
Nope, we want to get parts of the tiles and so we need to work with large numbers because RPG Maker can't work with decimal points.
We all know the screen is exactly 20 tiles across and 15 tiles down and that is reflected perfectly above.

160 pixels = 10.00 tiles
120 pixels = 07.50 tiles

This is a simple percentage calculation system above anything else, a tile consists of 16 pixels, thus 1 pixel should equate to about 6% of a tile, for every pixel the picture moves, it's going a further 6% onto a tile, this results in the variables increasing by 6 for every pixel moved.

As stated beforehand, this system on its own isn't very useful, but think of everything it can be used for, Platformers, Shooting Games and Arcade Games to say the least.
Anything that requires boundaries to be set can benefit from this greatly.



Click to Return to the Tutorials Page