This is how to make an intro for your game...
Were going to draw an image and put some text on it...
A simple example is:-
[Note: The following code goes into your game.js file...]
EvaluateSystemScript("time.js");
function IntroScreen()
{
GetSystemFont().drawTextBox(0,0,GetScreenWidth(), GetScreenHeight(), 0, "lots of text here...");
FlipScreen();
Delay(5000);
}
But if you have lots of text to show, that example is rubbish.
So here is a much better IntroScreen function that you might actually learn something from...
[Note: The following code goes into your game.js file replacing the code from above...]
EvaluateSystemScript("time.js");
function IntroScreen()
{
var x = 0;
var y = GetScreenHeight() + 10;
var h = 50;
var w = GetScreenWidth();
var txt = "Once upon a time in a land far away... There was a guy called heh, heh, blah, good luck!";
var background = LoadImage("intro.jpg");
while(y > -h)
{
background.blit(0,0);
GetSystemFont().drawTextBox(x,y, w, h, 0, txt);
FlipScreen();
Delay(75)
y -= 1;
}
}
Yeah, now you have an IntroScreen function, that you can call upon by using:-
IntroScreen();
So for example your game function may look like:-
function game()
{
IntroScreen();
}
The intro function essentially works by...
Decreasing the y value of the call to font.drawTextBox(x,y,w,h, offset, txt)...
By decreasing this y value in a loop, the text vertically rises.
Now, the while(y > -h) means while y is greater than minus h.
So while y is greater than -50 in this case.
Also, it blit's a background image at (0,0) each time...
This image could be a picture of some stars, to fully achieve a stars wars type intro.
Once the txt is drawn, it calls FlipScreen() which copies the drawing that we've done from the backbuffer to the screen.
If we wanted to add some music to this intro we could do so like so:-
var song = LoadSound("blah.mp3");
song.play(true);
IntroScreen();
song.stop();
So for example your game function may look like:-
function game()
{
var song = LoadSound("blah.mp3");
song.play(true);
IntroScreen();
song.stop();
}
This isn't actually changing the IntroScreen function at all.
Its just wrapping music around it.
Thats its folks, soon, I will cover arrays..
|