Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

I came here looking for exactly this sort of thing after I'd already started writing my own contraption, and realized "wait I should check first". Well done.

I attempted to modify it further to add anchor support but after failing and then checking the docks, am I correct in gleaning that this isn't possible if the contraption uses rtext? 'Twould be nice to have centered text at least.

(+1)

I don't see why this couldn't work for rtext. canvas.textsize[] and canvas.text[] both accept rtext and the latter accepts an anchor, provided the second argument supplies a bounding rectangle.

(1 edit)

Hmm. I had experimented with adding anchor to the canvas.text calls but it didn't seem to have any effect, so I took this quote as explanation as to why. But it occurred to me now that it's still wrapping the rtext left-wise so maybe I've misunderstood what anchors do here.

If x is an rtext table and pos is not a rectangle, the anchor a is ignored, text is drawn top-left aligned, and lines are not automatically wrapped.

Here's the modified version I made.

EDIT: got it working. Fixed version below. 

You appear to be using "anchor.value" when you mean "anchorType.text".

(1 edit) (+1)

Oh bugger, so I am. Type left over from an earlier version. Fixed that and now it works. Jolly good.

Here's the shadowtext version with anchor support:

%%WGT0{"w":[{"name":"title","type":"contraption","size":[461,33],"pos":[12,29],"show":"transparent","def":"shadowtext","widgets":{"canvas1":{"size":[461,33],"pattern":34},"field1":{"pos":[-186,122],"value":{"text":["","Title"],"font":["","deckbuilder"],"arg":["",""]}},"slider1":{"size":[273,25],"pos":[-52,117],"value":34},"slider2":{"size":[226,25],"pos":[300,117],"value":46},"anchorType":{"pos":[545,117],"value":"center"}}}],"d":{"shadowtext":{"name":"shadowtext","size":[100,100],"resizable":1,"margin":[0,0,0,0],"description":"Colour text, with a drop shadow! Exposes a redraw[] function if you need to refresh it manually for whatever reason.","version":2,"script":"on get_colour do\n slider1.value\nend\n\non set_colour x do\n slider1.value:x\n redraw[]\nend\n\non get_shadow do\n slider2.value\nend\n\non set_shadow x do\n slider2.value:x\n redraw[]\nend\n\non get_value do\n field1.value\nend\n\non set_value x do\n field1.value:x\n redraw[]\nend\n\non get_anchor do\n anchorType.text\nend\n\non set_anchor x do\n anchorType.text:x\n redraw[]\nend\n\non redraw do\n canvas1.clear[]\n \n size:canvas1.textsize[field1.value canvas1.size[0]-4]\n canvas1.pattern:slider2.value\n canvas1.text[field1.value 3,3,size anchorType.text]\n canvas1.pattern:slider1.value\n canvas1.text[field1.value 2,2,size anchorType.text]\nend\n\non view do\n redraw[]\nend\n\non get_redraw do\n redraw\nend","attributes":{"name":["value","colour","shadow","anchor"],"label":["Text","Colour (palette index)","Shadow (palette index)","Anchor"],"type":["rich","number","number","string"]},"widgets":{"canvas1":{"type":"canvas","size":[100,100],"pos":[0,0],"locked":1,"volatile":1,"script":"on click pos do\n \nend\n\non drag pos do\n \nend\n\non release pos do\n \nend","show":"transparent","border":0,"scale":1},"field1":{"type":"field","size":[100,20],"pos":[-186,189]},"slider1":{"type":"slider","size":[100,25],"pos":[-52,184],"interval":[0,47],"value":1,"style":"compact"},"slider2":{"type":"slider","size":[100,25],"pos":[65,184],"interval":[0,47],"value":1,"style":"compact"},"anchorType":{"type":"field","size":[100,20],"pos":[184,184]}}}}}

And the normal text version with anchor:

%%WGT0{"w":[{"name":"colourtext1","type":"contraption","size":[100,62],"pos":[104,163],"show":"transparent","def":"colourtext","widgets":{"canvas1":{"size":[100,62],"pattern":34},"field1":{"pos":[-186,151],"value":{"text":["","I seem to be in a spot of bother."],"font":["","ahmArrow"],"arg":["",""]}},"slider1":{"pos":[-52,146],"value":34},"a":{"pos":[73,151],"value":"center"}}}],"d":{"colourtext":{"name":"colourtext","size":[100,100],"resizable":1,"margin":[0,0,0,0],"description":"Like a text box, but with colour! With volatiles now. Exposes a redraw[] function if you need to refresh it manually for whatever reason.","version":1.2,"script":"on get_colour do\n slider1.value\nend\n\non set_colour x do\n slider1.value:x\n redraw[]\nend\n\non get_value do\n field1.value\nend\n\non set_value x do\n field1.value:x\n redraw[]\nend\n\non get_anchor do a.text end\non set_anchor x do a.text:x end\n\non redraw do\n canvas1.clear[]\n canvas1.pattern:slider1.value\n size:canvas1.textsize[field1.value canvas1.size[0]-4]\n canvas1.text[field1.value 2,2,size a.text]\nend\n\non view do\n redraw[]\nend\n\non get_redraw do\n redraw\nend","attributes":{"name":["value","colour","anchor"],"label":["Text","Colour (palette index)","Anchor"],"type":["rich","number","string"]},"widgets":{"canvas1":{"type":"canvas","size":[100,100],"pos":[0,0],"locked":1,"volatile":1,"show":"transparent","border":0,"scale":1},"field1":{"type":"field","size":[100,20],"pos":[-186,189]},"slider1":{"type":"slider","size":[100,25],"pos":[-52,184],"interval":[0,47],"value":1,"style":"compact"},"a":{"type":"field","size":[100,20],"pos":[73,189],"style":"plain"}}}}}