Sem Pausa...

Ver o tópico anterior Ver o tópico seguinte Ir em baixo

Sem Pausa...

Mensagem por DRcrusher em Seg 21 Mar 2011, 19:20

Então...
Dêem uma olhada nesse código de textbox:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// script name: show_textbox(x1,y1,x2,y2,text,sprite,img) //
// creator: max_buutz a.k.a Joel Arnott //
// year: 2005 //
// //
// description: Shows a text-box that can be used for dialogue, Game help and many more //
// //
// arguments: argument0 = x1 //
// argument1 = y2 //
// argument2 = x2 //
// argument3 = y2 //
// argument4 = Text //
// argument5 = Speaker Sprite //
// argument6 = Sub Image //
// //
// remarks: A stitch in time saves nine. //
// This script can be used in ANY event. //
// Credit is preferred but not needed. //
// Read the Game Information for more info. //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

{

var x1, y1, x2, y2, text, mar, spd, bcol1, bcol2, fcol1, fcol2, tcol1, tcol2, name;
var tlength, line_break, tchr, tchr_prev, tchr_next, tchr_w, tword_w, tword, ti, tw, th, thick, ckey, cspr, old_alpha;
var tword_chrprev, tword_pos, tpart, text_height, sprite, img, sw, sh;

// Declaring temporary variables

x1 = 170 - 170;
y1 = 172 - 170;
x2 = 470 - 170;
y2 = 308 - 170;
text = argument0;
sprite = spr_character;
img = argument1;
name = argument2;

// IMPORTANT! - Change the variables below to customize all text-boxes. \\

mar = 12; // The margin. E.g. how far from the edge the text stops/starts. Also effects portrait sprite etc.
spd = 35; // Text speed. Low = Fast, High = Slow

bcol1 = make_color_rgb(255,181,0); // Border color 1 (Top)
bcol2 = make_color_rgb(255,181,0); // Border color 2 (Bottom)
fcol1 = make_color_rgb(25,33,66); // Fill color 1 (Top)
fcol2 = make_color_rgb(25,33,66); // Fill color 2 (Bottom)
tcol1 = c_black; // Text color 1 (Top)
tcol2 = c_black; // Text color 2 (Bottom)

thick = 2; // Border Thickness
ckey = vk_enter; // Continue key. What key you press to speed up the text and close the text-box.
cspr = spr_continue; // The small sprite that appears in the bottom-right corner of the text-box, prompting you to continue.

// IMPORTANT! - Do not change anything else (unless of course you are customizing it yourself) \\

if (sprite_exists(sprite))
{
sw = sprite_get_width(sprite) + mar;
sh = sprite_get_height(sprite);
}
else
{
sw = 0;
sh = 0;
}

tlength = string_length(text);
ti = 0;
tw = 0;
th = 0;
line_break = false;
split = false;
text_height = string_height('A#A') - string_height('A');

if y1 + mar*2 + sh > y2 y2 = y1 + mar*2 + sh;
if x1 + mar*2 + sw > x2 x2 = x1 + mar*2 + sw;

// Giving temporary variables values

//if thick > 0 draw_rectangle_color(x1,y1,x2,y2,bcol1,bcol1,bcol2,bcol2,false); //Draw The Border
//draw_rectangle_color(x1 + thick,y1 + thick,x2 - thick,y2 - thick,fcol1,fcol1,fcol2,fcol2,false); //Draw the Textbox
draw_sprite(spr_textbox,0,x1,y1);

if (sprite_exists(sprite))
{
draw_sprite(sprite,img,x1 + mar - 2,y1 + mar - 2);
//draw_text(x1 + mar + 4,y1 + mar - 2 + sh, name);
}

repeat (tlength)
{
ti += 1; // Important! This is the variable holds the current position for reading in the text.
// It is used to read the current character and draw it.
tchr = string_char_at(text,ti); // Reads the current character.
tchr_prev = string_char_at(text,ti-1); // Previous character.
tchr_next = string_char_at(text,ti+1); // Next character.

// Begin Line-break character checking.
if line_break == true // If there there needs to be a line-break.
{
th += text_height;
if th > y2-y1-thick-mar*2 {split = true; break;};
tw = 0;
line_break = false;
}
if tchr != '\' && tchr_next == '#'
{
line_break = true;
}
if tchr == '\' && tchr_next == '#' continue;
if tchr == '#' && tchr_prev == '\' tchr = '\#';
// End Line-break character checking.

// Begin Pause character checking.
if tchr == '\' && tchr_next == '|' continue;
if tchr == '|' && tchr_prev != '\' {if keyboard_check(ckey) sleep(spd*2) else sleep(spd*4); continue;}
// End Pause character checking.

tchr_w = string_width(tchr);
if string_char_at(text,ti-1) == ' ' or string_char_at(text,ti-1) == '.' or string_char_at(text,ti-1) == '-' or ti == 1
// Checks if it is currently at the beginning of a new word.
{
tpart = string_copy(text,ti,tlength-ti);
var temp1, temp2, temp3;
temp1 = string_pos('-',tpart);
if temp1 == 0 temp1 = 10000;
temp2 = string_pos('.',tpart);
if temp2 == 0 temp2 = 10000;
temp3 = string_pos(' ',tpart);
if temp3 == 0 temp3 = 10000;
temp4 = string_pos(' ',tpart);
if temp4 == 0 temp4 = 10000;
temp5 = string_pos(' ',tpart);
if temp5 == 0 temp5 = 10000;
// This bit is simply a 'stop-gap' solution to a slight problem. It still works.
tword_pos = min(temp1,temp2,temp3,temp4,temp5);
// Spaces, full-stops (or periods) and hyphens represent the end of 'words'. This finds the closest one (the correct one)
tword = string_copy(text,ti,tword_pos-1);
// Reads the word about to be typed.
tword_chrprev = ''; // Initiates previous character variable. Empty because at start of string (no prev. character).
for (i = 1; i <= string_length(tword); i += 1;)
{
tword_chr = string_char_at(tword,i); // Reads a character from the word and places in variable.
if tword_chr == '#' && tword_chrprev != '\' {tword = string_delete(tword,i,1) i -= 1;};
// Removes newline characters when they are not specially included using the '\' character.
if tword_chr == '|' && tword_chrprev != '\' {tword = string_delete(tword,i,1); i -= 1;}
// Removes pause characters when they are not specially included using the '\' character.
tword_chrprev = tword_chr;
// Places current character into previous character variable for use in next repetition.
};

tword_w = string_width(tword); // Variable for the width of tword (the word read from the text).
if x1 + mar + tw + tword_w + sw > x2-mar // If the text width + the word width goes outside the margins of the text box
{
th += text_height; // Go down a line.
if th + string_height(tchr) > y2-y1-thick-mar*2 {split = true; break;};
// If the new text height is more than the bottom margin, split the text-box into two in succession
tw = 0; // When you reach the end of a line, go back to the start. Think of a typewriter.
};
};

draw_text_color(x1+mar+tw+sw,y1+mar+th,tchr,tcol1,tcol1,tcol2,tcol2,1);
// Draws the character.
tw += tchr_w;
// Adds the width of the character to tw (text width). This moves the drawing over a bit after each character.

screen_refresh();
// You see screen_refresh() quite a bit in this script. This is because the game is drawing onto the internal image.
// The internal image is invisible. When the drawing events are performed, first the room background is drawn,
// erasing anything you drew on the internal image. But when you use screen_refresh(), the internal image is placed
// directly onto the screen.

if keyboard_check(ckey) sleep(spd/2) else sleep(spd);
// Pauses after each drawn letter.
// If you are holding the 'Continue' key, it only pauses for half the normal time.
};

if cspr != -1 draw_sprite(cspr,-1,x2-mar-sprite_get_width(cspr)+sprite_get_xoffset(cspr),y2-mar-sprite_get_height(cspr)+sprite_get_yoffset(cspr));
// Draws the 'Continue' sprite.
screen_refresh();

do {keyboard_wait();} until (keyboard_check(ckey));
// Freezes game until you press the 'Continue' key.

// Start of darkening
/*old_alpha = draw_get_alpha();
draw_set_alpha(0.4);
draw_rectangle_color(x1,y1,x2,y2,c_black,c_black,c_black,c_black,false);
draw_set_alpha(old_alpha);*/
// End of darkening. After text-box has 'lost focus' (e.g. continue key pressed) it darkens.

screen_refresh();

if split == true show_textbox(string_copy(text,ti,tlength-ti+1),img);
// If there is too much text to fit on one text-box, bring up another one to show the rest.

}

Se alguém puder fazer a gentileza de fazer esse mesmo código mas sem que o jogo que está acontecendo em volta seja pausado eu agradeceria...

Obs: O Código está aberto para uso, pois eu não possuo os direitos de uso e o autor disponibiliza-os abertamente...

DRcrusher Fight!

DRcrusher

Número de Mensagens : 17
Data de inscrição : 30/01/2011
Reputação : 0
Insignia 1 x 0 Insignia 2 x 0 Insignia 3 x 0
Prêmios
   : 0
   : 0
   : 0

Voltar ao Topo Ir em baixo

Re: Sem Pausa...

Mensagem por GameMakerTutoriais em Qui 24 Mar 2011, 08:33

A linha já estava até comentada, aliás:

Código:
do {keyboard_wait();} until (keyboard_check(ckey));
// Freezes game until you press the 'Continue' key.

Troque por isso:
Código:
if not keyboard_check(ckey) then exit;

GameMakerTutoriais

Número de Mensagens : 800
Data de inscrição : 29/01/2011
Reputação : 26
Insignia 1 x 0 Insignia 2 x 0 Insignia 3 x 0
Prêmios
   : 0
   : 0
   : 0

Voltar ao Topo Ir em baixo

Ver o tópico anterior Ver o tópico seguinte Voltar ao Topo

- Tópicos similares

 
Permissão deste fórum:
Você não pode responder aos tópicos neste fórum