To get tile slot IDs we will create the GetSlotX And GetSlotY methods, as follows:
1. First add the method
GetSlotX
into the game class with a parameter of the typeftObject
.Method GetSlotX:Int(obj:ftObject)
2. Store the
x
position of the object. It is divided by its width and stored in the local variablexp
with the type INT.Local xp:Int = obj.GetPosX()/obj.GetWidth()
3. Return
xp
and close the method.Return xp End
4. Next, add the method
GetSlotY
to thegame
class.Method GetSlotY:Int(obj:ftObject)
5. Store the
y
position of the object. It is divided by its width and stored in the local variableyp
with the type INT.Local yp:Int = obj.GetPosY()/obj.GetHeight()
6. Return
yp
and close this method.Return yp End
The two methods that you have added will let you determine the slot positions of a gem inside the tile map.