Jump to content


Photo
- - - - -

Textbox Tutorial


  • Please log in to reply
16 replies to this topic

#1 drazzke

drazzke

    GMC Member

  • New Member
  • 1084 posts

Posted 03 February 2008 - 06:38 AM

Replies to topics in this forum are held to a high standard. Reviews must have a critique or suggestion for use to be approved. Read the rules here.


I put together a simple textbox engine that actually works pretty well. It creates a textbox with your text, in the center of the screen/view.

Title:TextBox Tutorial
Download: link - Host: box.net
No registered functions used.
Filetype: gmk file (about 30 kb)

The script below works in GM7.0 and GM6.1 as far as I know!

Create a new script, and call it "scr_textbox" - Place the following code in the new script:
//Argument0=Title
//Argument1=Text
//Argument2=Displayed textbox or not
//Argument3=Background Colour
//Argument4=Border Colour
//Argument5=Background Alpha
//Argument6=Other Messages/Continue Button/Whatever


contkey=argument2
if contkey=false {exit;}

title=argument0
text=argument1
col1=argument3
col2=argument4
alpha=argument5
finish=argument6

centerx=view_xview+view_wview/2
centery=view_yview+view_hview/2

draw_set_color(col1)
draw_set_alpha(alpha)
draw_set_font(fn_message_main)
if string_width(text)>string_width(finish)
{
	draw_rectangle(centerx-string_width(text)/2-20,centery-string_height(text)/2-30,centerx+string_width(text)/2+20,centery+string_height(text)/2+30,false)
	draw_set_color(col2)
	draw_set_alpha(1)
	draw_rectangle(centerx-string_width(text)/2-20,centery-string_height(text)/2-30,centerx+string_width(text)/2+20,centery+string_height(text)/2+30,true)
}
else
{
	draw_rectangle(centerx-string_width(finish)/2-20,centery-string_height(finish)/2-30,centerx+string_width(finish)/2+20,centery+string_height(finish)/2+30,false)
	draw_set_color(col2)
	draw_set_alpha(1)
	draw_rectangle(centerx-string_width(finish)/2-20,centery-string_height(finish)/2-30,centerx+string_width(finish)/2+20,centery+string_height(finish)/2+30,true)
}

draw_set_halign(fa_center)
draw_set_font(fn_message_title)
draw_set_color(col2)
draw_text(centerx,centery-string_height(text)/2-15,title)
draw_set_halign(fa_left)
draw_set_font(fn_message_main)
draw_text(centerx-string_width(text)/2,centery-string_height(text)/2,text)
draw_set_halign(fa_center)
draw_set_font(fn_message_end)
draw_text(centerx,centery+string_height(text)/2+5,finish)

Then, create 3 fonts of your choosing, naming them:
fn_message_title
fn_message_main
fn_message_end

Then, create an object, and put this in the create event:
i=0
show[i]=false
text[0]='This is part 1'
text[1]='This is part 2'
text[2]='This is part 3'
text[3]='This is part 4'
text[4]='etc...'
text[5]='etc...'
text[6]=''

//You can have as many as you like, just make the last one be equal to ''
Put this in the keyboard_pressed event that will be the continue key:
if show[i]=true
{
	if text[i]!=''{i+=1;}
	if text[i]!=''{show[i]=true} else {show[i]=false}
	show[i-1]=false
}
Put this in the draw event:
scr_textbox('Title!',text[i],show[i],c_white,c_black,0.8,'Click Enter to Continue!')

Once you have that all set up, just set show[0]=true when you want the textbox to start. (You could just set it to true in the create event).



If used, you don't need to give credit.
-Drazzke
  • 0

#2 JishHD

JishHD

    GMC Member

  • New Member
  • 1428 posts
  • Version:GM:Studio

Posted 03 February 2008 - 07:47 PM

Very nice codes! It seems easy to modify and put into games, and it has a lot of functionality. Good job!
  • 0

#3 qwertyuil390

qwertyuil390

    GMC Member

  • GMC Member
  • 232 posts
  • Version:GM8.1

Posted 04 February 2008 - 01:00 AM

Wow, this actually is very nice. I like how the text box stretches according to the amount of text :)
  • 0

#4 drazzke

drazzke

    GMC Member

  • New Member
  • 1084 posts

Posted 06 February 2008 - 04:10 AM

Glad you both liked it :D
  • 0

#5 LRG

LRG

    GMC Member

  • GMC Member
  • 687 posts

Posted 29 February 2008 - 04:44 AM

this script can be optimized by making everything into one script.
you should try to make the text type letter-by-letter which shouldn't be too hard.
  • 0

#6 headline@live.se

headline@live.se

    GMC Member

  • New Member
  • 1298 posts

Posted 29 February 2008 - 05:32 PM

Wicked!!! it works for gm6?!?!
  • 0

#7 93dt

93dt

    GMC Member

  • New Member
  • 36 posts

Posted 06 March 2008 - 07:39 AM

This is cool! but how could you change it so that the box is at the bottom center instead of the middle center? Im using Game Maker 6.1 by the way!
thx 93dt
  • 0

#8 drazzke

drazzke

    GMC Member

  • New Member
  • 1084 posts

Posted 11 March 2008 - 01:53 AM

Thanks for the comments and suggestions!

93dt, it is pretty simple.
Just replace this code, that is found in scr_textbox:
centerx=view_xview+view_wview/2
centery=view_yview+view_hview/2
with
centerx=view_xview+view_wview/2
centery=view_yview+view_hview-string_height(text)-30

I have tested this, and it works :D
  • 0

#9 Reegan

Reegan

    GMC Member

  • New Member
  • 463 posts

Posted 12 March 2008 - 06:44 PM

You probably wont wanna hear this but, I noticed two bugs and here they are

1. pressing space during one of the texboxes somewhere in the middle maybe brings you back to the a first textbox but doesnt show it
look down at the bottom after youv pressed space

2. this is sort of linked with the other one up top
when you press space at the mid textbox or somewhere around there
the textboxes for some reason change order :S , like you wuld get the last textbox come up first! :S

fix those and its a pretty cool script
  • 0

#10 pngnman

pngnman

    GMC Member

  • New Member
  • 178 posts

Posted 02 May 2009 - 07:24 PM

this almost perfect, but how do you change the depth of the background of the textbox. It is below anything that has a negative depth, so it looks weird.
  • 0

#11 Shorooq

Shorooq

    GMC Member

  • GMC Member
  • 526 posts

Posted 05 February 2010 - 07:43 AM

how to make the box bigger


x1=0
x2=640
y1=200
y2=480??

Edited by Shorooq, 05 February 2010 - 09:04 AM.

  • 0

#12 Awesomeness

Awesomeness

    GMC Member

  • New Member
  • 367 posts

Posted 14 February 2011 - 09:17 AM

I know this is an old topic...
But does anyone know how to make the title change, like a bunch of characters having a conversation?
BTW the whole thing is very well done. Really useful. :)
  • 0

#13 bbman1999

bbman1999

    GMC Member

  • GMC Member
  • 187 posts
  • Version:GM8

Posted 23 March 2011 - 02:07 AM

I don't understand what to put for arguments 2, 5, and 6. Please tell me. :(

Edited by bbman1999, 23 March 2011 - 02:09 AM.

  • 0

#14 bbman1999

bbman1999

    GMC Member

  • GMC Member
  • 187 posts
  • Version:GM8

Posted 23 March 2011 - 02:22 AM

Never mind I don't need to know. I thought this was about a typing text box. :( Dose any one know how to make on of those? Like where you Type something and it gets saved as a variable, Because I need to make a cheat engine where you type codes then hit enter to activate it. Please help.

Edited by bbman1999, 23 March 2011 - 02:23 AM.

  • 0

#15 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 16031 posts
  • Version:GM:Studio

Posted 07 July 2011 - 12:42 AM

Std Msg: Please use the tutorial template header (The Tutorial Clean Up Crew).
Std Msg: Please remove the Local Moderator Said quote (The Tutorial Clean Up Crew).
  • 0

#16 QW3RTYPOUNC3S

QW3RTYPOUNC3S

    GMC Member

  • New Member
  • 4 posts
  • Version:Mac

Posted 29 July 2014 - 01:39 PM

How do the arguments work? Can someone give me an example?


  • 0

#17 iiRomano

iiRomano

    GMC Member

  • GMC Member
  • 879 posts
  • Version:Unknown

Posted 29 July 2014 - 01:49 PM

How do the arguments work? Can someone give me an example?

Please dont necro bump.

Instead reviving an old topic just make one yourself.


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users