Saturday, June 12, 2021

【GAMEMAKER】Marquee

Information about object: object0

Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

//the first character to display
tc = 1
//the width of the display in characters
w = 20
//initial delay until it starts scrolling
//also see alarm - this is a bit more delayed
 //to give you time to read the first letters
alarm = 10
//the text, add empty space at the end so you don't get "ee?How"
text = "How do you like my marquee?  "
//the font
font_name = "Courier New"
font_size = 12
Alarm Event for alarm 0:
execute code:

//increment the first displayed character by 1
tc += 1
//if the first displayed character exceeds the string length
 //start over again
if tc > string_length(text) { tc = 1 }
//start the countdown until scroll again
alarm = 10

Draw Event:
execute code:

//calculate the last character displayed
last = min(tc+w,string_length(text)+1)
//calculate the wraparound last character displayed
first = max(0,tc+w-last)
//display the marquee at x,y
draw_text(x,y,string_copy(text,tc,last-tc)+string_copy(text,0,first))

No comments:

Post a Comment