PDA

View Full Version : Text Script & Real Time Clock(Sphere)


Booda Sack
May 28th, 2005, 11:24 AM
Here is a text script which you will need to display the clock time or any text.

function Text(str,x,y)//str is the text you want to print
{
var myfont = LoadFont("epokefont.rfn");
var windowstyle = LoadWindowStyle("bluewhite.rws");
var x = x;
var y = y;
var width = GetScreenWidth()-32;
var height = myfont.getStringHeight(str, width);



while (!IsKeyPressed(KEY_CTRL))//shows text untill you press CTRL
{

if (IsMapEngineRunning())
RenderMap();

windowstyle.drawWindow(x, y, widht, height);
myfont.drawTextBox(x, y, width, height, 0, str);

FlipScreen();
}
}

Usage of the text script would be something like:
Text("Sphere Text Script",10,10);

Here is another simple but very useful script.
Clock:

var time //Store the time object
var hours //Store the hours part of the time object
var mins //Store the minuets part of the time object
var secns//Store the second part of the time object

function thetime(){
time = new Date()
hours = time.getHours()
mins = time.getMinutes()
secns = time.getSeconds()
}


To put the time to the screen you would do:

thetime()//Update the time variables
Text("The time is:"+hours+":"+mins+":"+secns,20,20);

Or you could do,there is no need for the hour,min secns variable:

thetime()//Update the time variables
Text("The time is:"+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds(),20,20);


But I just find its easier to type the first one.

Dawson
May 28th, 2005, 11:26 AM
I'm pleased to see you're making these Sphere tutorials, Booda. It'll really help a lot of people who want to learn it.

Sorye HK
May 28th, 2005, 11:50 AM
I guess that this is the first Sphere tut here! Looking forward to more, Booda.

BlackCharizard
May 31st, 2005, 06:12 AM
Where can I get sphere? Some1 help

Booda Sack
May 31st, 2005, 07:33 AM
http://sphere.sf.net

But the best sphere community is http://www.spheredev.net