***************************
Aeal�s platform Camera Tutorial.
***************************
Intro:
This is a basic tutorial for creating a nice camera in construct for Side Scrolling platform games. Its pretty easy to do you do need to know how to do a few things though before you can start.
1. Make Private Variables in sprites
2. Basic event sheet know how.
3. Ability to translate my Pseudocode into events
How the Pseudocode is set up.
+These are the conditions
-These are the actions
The end result:
Your character will be in the lower left hand corner of the screen when he is walking to the right. When he starts walking to the left the camera will scroll and stop till he is in the same position on the right hand side of the screen. Creating a nice scrolling effect with little to no hard coded math, that can be easily manipulated by Private Variables.
What you need to create in construct:
4 sprites
-Character
-Camera
-Back Camera
-Forward camera
The Camera and Camera points Should be as thin as possible height dosent matter so much as of right now.
Private Variables (named what you want but here is what I named them and attached them to)
-Walking Direction �Character Sprite
-Yoffset-Camera
-Xoffset -Camera
-Scroll rate-Camera
-FowardCamPoint-Camera
-BackCamPoint-Camera
Here is what each variable will do in the code:
Walking direction - This is a flag that will tell us which way the character sprite is walking.
Yoffset- This will be how high above your head the camera is.
Xoffset- This is how far away each camera will be away from the character
Scroll rate- This is how fast the camera will scroll(in pixles per tick)
FowardCam - This is another flag variable telling us when the camera overlaps the forward camera
BackCam- Does the same as the Forward camera but with the back end instead.
Now for some eventing:
NOTE Creating event sheets:
I personally like to keep all my event sheets separated. So Ill have like player General events that control all the players movements and animation. This is where I would set his walking Flag. I would also have a separate camera event sheet so I know where it is and what is does. If you using this in a game then I would suggest putting this in a separate event sheet or at the least in a separate group so you know where it is.
Setting our Flags:
First we will set the flags to go off when we want them too. So if you have a Player event sheet go there. Here is the event that I used for setting my flag:
+ A button is pressed
-Set player.value(�Walking direction�) to -1
+ D button is pressed
-Set player.value(�Walking direction�) to 1
Since I am using WASD as my platform controls I set the flags to go off when A and D are pressed you could change them the any keys you want or experiment with negative and positive speeds or on control pressed, but i've found this works nicely.
Here is our next bit of code to set the camera flags.
+ Camera.X < = BackCamPoint.x
-Camera.value('Backcam') = 1
+Camera.x >= FrontCamPoint.x
-Camera.Value('Frontcam') = 1
These let us know when to stop the camera scrolling so it does not go past your Xoffsets.
Next its finally time to script the camera movements in. (Make sure you also Have the Center Veiw on me for the Camera ticked on.)
+Always(every tick)
-Set BackCamPoint X Postion to Player.x - Camera.Value('Xoffset')
- Set FrontCamPoint X Postion to Player.x + Camera.Value('Xoffset')
-Set BackCamPoint Y Postion to Player.y - Camera.Value('Yoffset')
- Set FrontCam Y Postion to Player.y - Camera.Value('Yoffset')
-Set Camera Y position to Player.Y � Camera.Value(�YOffset�)
- Scroll to object(Camera) //Only use this if "Center Veiw On Me" does not work.
These will have the two Camera Postion Always attached to your Character at the offsets in the Camera Private variables. You Might also want to make the player a Container for all the camera objects.
Now for the Scrolling behaviors.
+ Player.Value('walking Direction') = 1
+ Camera. Value('Fowardcam') = 0
-Set X postion "Camera" = Camera.X + Camera.Value('Scroll Rate')
+ Player.Value('walking Direction') = 1
+ Camera. Value('Fowardcam') = 1
-Set X postion "Camera" = Foward Cam.X
The first event works by checking to see if the player is walking right? Yes. Is My camera overlapping my forward Camera position? No. Then I'll Add to the cameras X position at the scroll rate. And it keeps checking till they over lap.
The second event works by Checking the same values but if they are both true then it sets the camera at the camera point and does not scroll any more. now we just program a reversal of that same code but with the back Camera point.
+ Player.Value('walking Direction') = -1
+ Camera. Value('Backcam') = 0
-Set X postion "Camera" = Camera.X -Camera.Value('Scroll Rate')
+ Player.Value('walking Direction') = -1
+ Camera. Value('Backcam') = 1
-Set X postion "Camera" = BackCam.X
That is it your done you should have a nice Scrolling camera with no hard coded variables! Now just run the debugger and play with your offsets and scroll rate to fine tune you camera! Hoped this worked for you Here is a .Cap with the code I have give here, for reference use. Let me know how you like it.
To the CAP! http://www.mediafire.com/?sharekey=3db63aaedf0f1cd9d2db6fb9a8902bda