Page 1 of 1

(SOLVED) Trouble with Drawing and Not Drawing an object

Posted: Mon Jun 30, 2014 3:09 am
by Biphe
The problem I seem to be having is that the text box is not dissapearing smoothly but suddenly. I was wondering if I should use a timer to smoothen the transition from drawn to not drawn.

The love file is included.
Press k to draw the box and q to undraw it.
Also you can move the little player box with the arrow keys, although he won't move with the textbox around which is intentional.'

Re: Trouble with Drawing and Not Drawing an object

Posted: Mon Jun 30, 2014 6:14 am
by micha
Smoothing definitely looks better. Here is a quick solution for your problem.
textbox.love
(729.97 KiB) Downloaded 159 times
I extended the textbox-drawing function so that it takes an alpha-value as parameter. Then, when "k" is pressed, each frame the alpha value is changed until it reaches 255. If the textbox is not running, then the alpha value is lowered until zero. The math.min and math.max make sure that the alpha always stays between 0 and 255.

Code: Select all

if msg_box.running then
  alpha = math.min(alpha + 2550*dt,255)
else
  alpha = math.max(alpha - 2550*dt,0)
end
If you replace the number 2550 in these lines you can make the transition faster or slower.

Re: Trouble with Drawing and Not Drawing an object

Posted: Tue Jul 01, 2014 1:18 am
by Biphe
Thanks