Pipmak Game Engine Wiki
Status: Alpha
Brought to you by:
cwalther
Show text message in Pipmak isn't a very simple task...
If you have a door in a cubic room thats locked.. how do you go about adding a message at the foot of the screen which explain that its locked?
I have resolve it in this manner:
1. You have to create an overlay node, for example numbered "100", with this lua code:
:::lua
--------------------------------------------------------------------------------
--
-- node.lua -- Overlay message node
--
--------------------------------------------------------------------------------
-- Usage:
-- pipmak.overlaynode(100):message("write","Message to display")
-- or
-- pipmak.overlaynode(100):message("write","Message",{size=20,delay=2,posy=-100})
--
-- size: size of the text (max=30)
-- posy: y position of the text (posy>0 start from top, posy<0 start from bottom)
-- delay: after delay seconds the overlay will be closed
--
-- 1) if you don't use delay, another write substitute last message
-- 2) if you want remove message use delay option or simply close overlay
--
-- Globals: textpatch
--------------------------------------------------------------------------------
panel { pipmak.newimage( pipmak.screensize() ) }
textpatch = patch {x=0, y=0, image = pipmak.newimage(1,1) }
messages {
write = function(text,options)
if options == nil then options={} end
if options.size == nil then options.size = 14 end
if options.posy == nil then options.posy = -10-options.size end
local width,height = pipmak.screensize()
local textImage = pipmak.newimage(width,30):color(1,1,1,0):fill()
local font = "../resources/Vera.ttf"
if options.posy<0 then options.posy=height+options.posy end
--draw a black border around white text
textImage:color(0,0,0,1)
textImage:drawtext(width/2-1,1,text,font,options.size,pipmak.center)
textImage:drawtext(width/2-1,3,text,font,options.size,pipmak.center)
textImage:drawtext(width/2+1,1,text,font,options.size,pipmak.center)
textImage:drawtext(width/2+1,3,text,font,options.size,pipmak.center)
textImage:color(1,1,1,1)
textImage:drawtext(width/2,2,text,font,options.size,pipmak.center)
textpatch:move{x=0,y=options.posy,w=width,h=30}
textpatch:setimage(textImage)
if options.delay~=nil then
pipmak.schedule(options.delay,
function()
pipmak.thisnode():closeoverlay()
end)
end
end
}
2. to show your message, you have to add next code to onenternode section of your node
:::lua
onenternode (function()
pipmak.overlaynode(100):message("write","Message to display",{size=20,delay=4,posy=-30})
end)
3. You can choise: