Jump to content


Photo

Custom Font Through Sprites


  • Please log in to reply
7 replies to this topic

#1 flxp

flxp

    GMC Member

  • GMC Member
  • 325 posts
  • Version:GM8

Posted 15 December 2011 - 03:10 AM

I want to make a font using an animated sprite.(not gamemaker's font renderer)

Create Event
//My Variables for my sprite
Char[0]="A"
Char[1]="B"
Char[2]="C"
Char[3]="D"
Char[4]="E"
Char[5]="F"
Char[6]="G"
Char[7]="H"
Char[8]="I"
Char[9]="J"
Char[10]="K"
Char[11]="L"
Char[12]="M"
Char[13]="N"
Char[14]="O"
Char[15]="P"
Char[16]="Q"
Char[17]="R"
Char[18]="S"
Char[19]="T"
Char[20]="U"
Char[21]="V"
Char[22]="W"
Char[23]="X"
Char[24]="Y"
Char[25]="Z"
Char[26]="-"
Char[27]="."
Char[28]=","
Char[29]=" "
Char[30]="0"
Char[31]="1"
Char[32]="2"
Char[33]="3"
Char[34]="4"
Char[35]="5"
Char[36]="6"
Char[37]="7"
Char[38]="8"
Char[39]="9"
Char[40]="a"
Char[41]="b"
Char[42]="c"
Char[43]="d"
Char[44]="e"
Char[45]="f"
Char[46]="g"
Char[47]="h"
Char[48]="i"
Char[49]="j"
Char[50]="k"
Char[51]="l"
Char[52]="m"
Char[53]="n"
Char[54]="o"
Char[55]="p"
Char[56]="q"
Char[57]="r"
Char[58]="s"
Char[59]="t"
Char[60]="u"
Char[61]="v"
Char[62]="w"
Char[63]="x"
Char[64]="y"
Char[65]="z"
Char[66]="!"
Char[67]="?"
Char[68]="("
Char[69]=")"
Char[70]="<"
Char[71]=">"

FullString="Hello, What is your name??"
String=""
Pos=0

Draw Event
for (i=0; i<Pos; i+=1)
{
draw_sprite(Font,/*???*/,x+i*7,y)
}
if(Pos<string_length(FullString)){Pos+=1}
String=string_copy(FullString,0,Pos)
//i've tried many things after i noticed i can't do this:
//Char["A"]=0

im all confussled now....
plz help if you understand(im sure its easy, but i just lost my memory :sweat: )
  • 0

#2 ookami125

ookami125

    GMC Member

  • GMC Member
  • 217 posts
  • Version:GM:Studio

Posted 15 December 2011 - 03:23 AM

just msg me if you need any more help
create
Char="ABCDEFGHIJKLMNOP"//ect...
draw
for (i=0; i<Pos; i+=1)
{
draw_sprite(Font,string_pos(Char,string_char_at(FullString,i)),x+i*7,y)
}
if(Pos<string_length(FullString)){Pos+=1}
String=string_copy(FullString,0,Pos)

Edited by ookami125, 15 December 2011 - 03:27 AM.

  • 0

#3 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 15 December 2011 - 03:42 AM

If you arrange sub-images of the sprite in the order of ascii table (filling unnecessary characters with blank sub-images) you can easily take the sub-image number that corresponds to each letter with ord(). Supposing that a white space " " is the first sub-image that has the smallest ascii code:
draw_sprite(Font, ord(string_char_at(FullString, i+1)) - ord(" "), ...
By the way, character index of a string starts with 1, so you should use string_char_at(str, 1) to take the first letter so on. The same applies to string_copy (the second argument shouldn't be 0 but 1.) I have no idea what the latter half of your code is for, though.

Also, you could turn the sprite into a font using font_add_sprite and then draw the text with draw_text as usual.

Edited by torigara, 15 December 2011 - 03:44 AM.

  • 0

#4 A saurus1

A saurus1

    GMC Member

  • Sandbox Moderators
  • 1593 posts
  • Version:GM8.1

Posted 16 December 2011 - 08:01 PM

I think he wants the sprite to be animated, though.
  • 0

#5 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 20 December 2011 - 03:37 PM

First off...

Are the letter sprites all in the same sprite?
A: sprite 0 - 4
B: sprite 5 - 9
C: sprite 10 - 14
And so on...

Or are they seperated?
A: spr_letter_ca
B: spr_letter_cb
C: spr_letter_cc
And so on...
  • 0

#6 A saurus1

A saurus1

    GMC Member

  • Sandbox Moderators
  • 1593 posts
  • Version:GM8.1

Posted 13 June 2012 - 01:49 AM

I'm not sure I understand where you're going, filulius...

Also, flxp, couldn't you use font_add_sprite()? Or are you using lite?
  • 0

#7 Gamer3D

Gamer3D

    Human* me = this;

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

Posted 13 June 2012 - 08:22 PM

The people suggesting subimages for each character had the right idea.

You have (at least) two ways to go about this:
  • Give each character N subimages (N must be the same for each letter). Then char_subimg = (ord(char) - ord(first_char)) * N + (anim_subimg mod N)
  • Alternately, have each subimage hold every character and draw them as needed with draw_sprite_part.

  • 0

#8 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 13 June 2012 - 11:59 PM

to continue Gamer3D's list of methods(and to reiterate filulilus's multi sprite method)
3rd option:

A: spr_letter_ca
B: spr_letter_cb
C: spr_letter_cc
...


and store the sprite id for each letter in an array so that sprite_char[4] would be "E". this would be bad if you needed capitols aswell as lower as youd need 52 sprites ;)
draw_sprite(sprite_char[letter],image_index,...
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users