|
Submit
Your Own Code
PSP Lua CodeBase : Typewriter EffectDescription:
this code gives you the known typewriter effect when using
texts.
often used in RPG's ;)
this code is copy pasted from my work, you gotta havea little
lua knowledge to
convert it into your own project, comments should help you out a
little though.
if you wanna test, copy / paste this into a .lua file, and when
playing press the
cross button to start it.
-- EVILMANA.COM PSP LUA CODEBASE
-- www.evilmana.com/tutorials/codebase
-- Typewriter Effect for Text
-- SUBMITTED BY: dennis van den broek
-- Code : DS (dialogue system)
-- Autor: Dennis van den broek
white = Color.new(255, 255, 255)
-- initialise if the DS (dialogue system) should be called
DS_set = 0
-- strings used for the effect
DS_str = { }
DS_str[1] = "This is a typewriter machine test..."
DS_str[2] = "This code is a test which can be used freely,"
DS_str[3] = "in any type of game, credits are allways welcome"
-- temp string that stores the current to write string
write_str = ""
str_length = 0
-- counter for holding where on the string we are
i = 1
num = 1
-- sets the DS on or off
function init_DS(type)
if type == 1 then
DS_set = 1
else
DS_set = 0
num = 1
end
end
-- checks what string to write, function should be upgraded
-- with detection of which
string to print
-- currently it's a simple placeholding code
function set_DS()
if num > 3 then
init_DS(0)
end
Typewriter(DS_str[num], 2, 10, 100)
end
-- the actual code, input the string you wanna print,
-- and how many characters per
frame you wanna show up...
function Typewriter(str, speed, DSx, DSy)
read_str = str
str_length = string.len(read_str)
if i <= str_length then
i = i+speed
write_str = string.sub(read_str, 1, i)
screen:print(DSx, DSy, write_str, white)
else
screen:print(DSx, DSy, write_str, white)
if pad:cross() and oldpad:cross() ~= pad:cross() then
i = 0
num = num + 1
end
end
end
-- main while loop
while true do
pad = Controls.read()
if pad:cross() and oldpad:cross() ~= pad:cross() then
init_DS(1)
end
if DS_set == 1 then
set_DS()
end
screen.waitVblankStart()
screen.flip()
screen:clear()
oldpad = pad
end
Back to CodeBase
|