The following files have been attached to this tutorial:
This tutorial hasn't been translated.
This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.
I have been asked by many of you how to control Hero on layout? Can I use Bound by or draw invisible wall to stop Hero going out of layer? How can I plot Hero X or Y? How can I show that player is at x=16 and y=16 in TEXT BOX? How can I use platform and 8Direction in same game?
There are many ways you can do all these things. Many of you will have different idea too. There is no set ways for these things because I might do it simple variables like x=1 y=1 up=2etc but, on other hand you might say Herox=1 HeroY=1 etc
Without going into too much how and when or what. Let’s create simple movement project and implement Text, hero Position, Platform, 8 Direction, Enemy collision, Enemy UID etc
Create new project and just live the default setting. Name it as you like.
Layer 0 call it hero
Now add second layer and set parallax to 0,0 this layout will be HUD
On layer hero create sprite and name it player add behaviour 8 Direction and Platform.
Now create one Enemy and make about many copies as you like
Now add 2 more Sprite and name them Trigger and place them in middle like below:
On our HUD layer create 4 text boxes and name them and do not add any text we will do that in Event Editor
Now open Event Editor and enter these Global Variables
That’s done now we add some actions
Add these lines
What we are saying here is at start set player position to posX=64 and posy=64 that meant X=80 and y = 80 because we already set posX and PosY to 16X16
Second line we are Disabled the platform
Third set our text saying Platform is off. (This mean 8 Direction is on)
Now keeping our player inside our layout without using Bound to Layout behaviour. This is not hard Ashley has made it easy for everyone with this behaviour but, sometime this is not suitable and you need to control hero your ways. This is where this tutorial comes in handy. Also it we will calculate position of hero and which platform movement hero is using. So add these lines of code and please be careful adding &&&& “”””” these character.
That’s our hero movement, positions, direction hero is moving etc
Now we have to keep our hero inside our layout. If we don’t then hero can go wondering outside layout. After hero gone outside you might not see him or her again. Add these lines after to keep hero inside layout.
This was not hard was it?
Now last bit where we have to decide is hero on platform or using 8 directions. Not that hard we already added Triggers. We can use that to set Platform or 8 Directions.
Note: Remember to hide your trigger1 and trigger2 I left it visible for tutorial
Once you add these lines and run it. You will notice decimal figures on Platform. I will leave that to you to round it off. At least you could do that. Good luck and bless you all