(SOLVED) Trouble with Drawing and Not Drawing an object

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Biphe
Prole
Posts: 13
Joined: Sun Jun 17, 2012 1:38 am

(SOLVED) Trouble with Drawing and Not Drawing an object

Post 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.'
Attachments
game.love
(733.21 KiB) Downloaded 147 times
Last edited by Biphe on Tue Jul 01, 2014 1:20 am, edited 1 time in total.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Trouble with Drawing and Not Drawing an object

Post by micha »

Smoothing definitely looks better. Here is a quick solution for your problem.
textbox.love
(729.97 KiB) Downloaded 158 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.
Biphe
Prole
Posts: 13
Joined: Sun Jun 17, 2012 1:38 am

Re: Trouble with Drawing and Not Drawing an object

Post by Biphe »

Thanks
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests