1 registered members (AndrewAMD),
1,014
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Scrolling Text Request
[Re: Minoterrae]
#422286
05/07/13 08:53
05/07/13 08:53
|
Joined: Feb 2012
Posts: 371
Dico
Senior Member
|
Senior Member
Joined: Feb 2012
Posts: 371
|
use file_str_read to read your text from txt file :
#include <acknex.h>
#include <default.c>
STRING* texttest = "";
TEXT* mytext =
{
string =texttest ;
pos_y = 10;
flags = SHOW;
}
function main ()
{
var fhandle = file_open_read("my text.txt"); // test.txt contains "this,is,a,test"
file_str_read(fhandle,texttest); // sTest now contains "this"
file_close(fhandle);
fps_max = 60;
mytext.pos_x =screen_size.x+10;
while(1)
{
mytext.pos_x -=1;
wait(1);
}
}
Last edited by Dico; 05/07/13 08:55.
|
|
|
Re: Scrolling Text Request
[Re: Dico]
#422293
05/07/13 09:55
05/07/13 09:55
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
I would edit Dico's example a bit Here it comes (thank you Dico):
// empty string:
STRING* texttest = "";
// text to be displayed:
TEXT* mytext = {
// set the string:
string = texttest;
// set flags:
flags = SHOW;
}
// main game funciton:
function main (){
// open the text file:
var fhandle = file_open_read("my.txt");
// read it's content, and save it into the string:
file_str_read(fhandle, texttest);
// close the text file (make sure, you close it after opening):
file_close(fhandle);
// place text at the far right corner:
mytext.pos_x = screen_size.x + 5;
// wait one frame (I'm not sure yet, but without this it causes error):
wait(1);
// get the width of the string:
var width = str_width(texttest, NULL);
// loop:
while(1){
// if text if gone to the left corner:
if(mytext.pos_x < -width){
// set it back to the upper right corner:
mytext.pos_x = screen_size.x + 5;
}
// scroll text to the left:
mytext.pos_x -= 10 * time_step;
// place text at the far right corner:
mytext.pos_y = screen_size.y - 50;
// wait one frame:
wait(1);
}
}
I hope this helps! Good luck! Edit: removed "200", cause that was causing problems with small text!! Greets
Last edited by 3run; 05/07/13 12:29. Reason: FIXED BUG!
|
|
|
Re: Scrolling Text Request
[Re: 3run]
#422299
05/07/13 10:24
05/07/13 10:24
|
Joined: Feb 2012
Posts: 371
Dico
Senior Member
|
Senior Member
Joined: Feb 2012
Posts: 371
|
I would edit Dico's example a bit Here it comes (thank you Dico):
// empty string:
STRING* texttest = "";
// text to be displayed:
TEXT* mytext = {
// set the string:
string = texttest;
// set flags:
flags = SHOW;
}
// main game funciton:
function main (){
// open the text file:
var fhandle = file_open_read("my.txt");
// read it's content, and save it into the string:
file_str_read(fhandle, texttest);
// close the text file (make sure, you close it after opening):
file_close(fhandle);
// place text at the far right corner:
mytext.pos_x = screen_size.x + 5;
// wait one frame (I'm not sure yet, but without this it causes error):
wait(1);
// get the width of the string:
var width = str_width(texttest, NULL);
// loop:
while(1){
// if text if gone to the left corner (play/remove 200 if needed):
if(mytext.pos_x < -width + 200){
// set it back to the upper right corner:
mytext.pos_x = screen_size.x + 5;
}
// scroll text to the left:
mytext.pos_x -= 10 * time_step;
// place text at the far right corner:
mytext.pos_y = screen_size.y - 50;
// wait one frame:
wait(1);
}
}
I hope this helps! Good luck! Greets you're the best
|
|
|
|