Page 1 of 1
Text size increase effect
Posted: Tue Oct 17, 2017 4:08 pm
by SWEdeAndy
Hi all,
I want to create an effect where a word in a field grows from textSize 5 to 100 (or something similar), so that it appears to start small and expand on the screen towards the viewer.
I’ve tried this, but it is not as smooth nor as fast as I would like it to be:
Code: Select all
local sCount
command prepareResize
put 5 into sCount
set the textSize of fld 1 to sCount
doResize
end prepareResize
command doResize
lock screen
add 1 to sCount
set the textSize of fld 1 to sCount
wait 0 milliseconds with messages ## Having this or not has no effect
if sCount < 100 then send doResize to me in 75 milliseconds
unlock screen
end doResize
If I increase textSize by bigger steps, it gets more choppy (naturally). If I set the send delay lower than around 75 milliseconds then it goes too fast for Livecode to keep up, it seems, resulting in textSize increasing by jumps of 2 or 3, making it more choppy.
So, is there a way to achieve a fast and smooth increase of the text? Am I on the wrong track? Should I turn the word into an image and increase the size of that instead?
I’ll be wanting to have this effect going on for several fields/words in parallel, e.g. names taken dynamically from a list, popping up all over the screen. So it has to be efficient enough not to cause lagging when used for multiple objects.
Any ideas?
/Andreas
Re: Text size increase effect
Posted: Tue Oct 17, 2017 6:40 pm
by [-hh]
Your approach is, TMHO, very dependent of the font quality (sizes must be scaled) and of all the other adjustments LC has to do for the field after changing the textsize.
Instead you could try the following approach that uses images (snapshots). Works here smoothly with 4 one-line-fields.
Depending on the number and size of your objects you may adjust the available parameters "tStep" and "tTimeStep".
Code: Select all
local sCount, iNum, w0, h0, l0, t0, tStep, tTimeStep
command doResize k,ii
lock screen; lock messages
add tStep to sCount[k]
set rect of img ii to \
(l0[k], t0[k], l0[k]+sCount[k]*w0[k]/100, t0[k]+scount[k]*h0[k]/100)
if sCount[k] < 100 then send "doResize k,ii" to me in tTimeStep millisecs
else
hide img ii; show fld k
end if
unlock screen; unlock messages
end doResize
-- demo with 4 fields
on mouseDown
lock screen; lock messages
put 4 into tStep -- increase parameter
put 32 into tTimeStep -- timeLoop parameter
repeat with j=1 to 4
put 0 into sCount[j]
put ("img"&j) into iNum[j]
-- delete, at least while developing
if there is an img iNum[j] then delete img iNum[j]
if there is no img iNum[j] then create invisible img iNum[j]
set resizequality of img iNum[j] to "best"
export snapshot from fld j to img iNum[j] as PNG
put the width of img iNum[j] into w0[j]
put the height of img iNum[j] into h0[j]
put the left of fld j into l0[j]
put the top of fld j into t0[j]
set rect of img iNum[j] to (l0[j], t0[j], l0[j]+1, t0[j]+1)
hide fld j
show img iNum[j]
end repeat
repeat with j=1 to 4
doResize j, iNum[j]
end repeat
unlock screen; unlock messages
end mouseDown
When using a factor (multiplicative step) that increases from 0 to 1 instead of the additive step you can also achieve kind of "easing" (increases faster for small sizes).
Re: Text size increase effect
Posted: Wed Oct 18, 2017 9:27 am
by SWEdeAndy
Brilliant, thanks a lot, that's just what I need!
I was thinking snapshots might be a solution, but haven't worked with that technique before. With this 'crash course' you have put me on the right track.
I've started to adapt your script to the kind of action I'm designing and it seems to work perfectly so far.
Thanks again!
/Andreas
Re: Text size increase effect
Posted: Wed Oct 18, 2017 12:47 pm
by MaxV
I suggest this solution easy and cool:
- put a field
- put a check box
- insert the following code in the checkbox
########CODE to copy and paste#######
on mouseUp
set the cursize of me to the textsize of field 1
cooleffect
end mouseUp
on cooleffect
if the hilite of me then
put the cursize of me into temp
if temp > 100 then set the incr of me to -1
if temp < 5 then set the incr of me to 1
add the incr of me to temp
set the textsize of field 1 to temp
set the cursize of me to temp
send cooleffect to me in 5 millisec
end if
end cooleffect
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-6#####
Re: Text size increase effect
Posted: Wed Oct 18, 2017 1:27 pm
by SWEdeAndy
Wow, yes, that works too! It basically does the same as my original script, but way faster and smoother.
What is it in my script that slows it down so much compared to this one?
Thanks!
/Andreas
Re: Text size increase effect
Posted: Wed Oct 18, 2017 8:21 pm
by jacque
The "wait 0" line is making it slower. I removed that and set the interval to 5 milliseconds in your original script and it looks very smooth to me:
Code: Select all
local sCount
command prepareResize
put 5 into sCount
set the textSize of fld 1 to sCount
doResize
end prepareResize
command doResize
lock screen
add 1 to sCount
set the textSize of fld 1 to sCount
if sCount < 100 then send doResize to me in 5 milliseconds
unlock screen
end doResize
Re: Text size increase effect
Posted: Wed Oct 18, 2017 8:55 pm
by SWEdeAndy
Indeed, the original script, when I try it again now in a new stack, is quite smooth.
The "wait 0" line seems to have marginal effect, but better without it. (I've learned somewhere that "wait 0..." would sometimes make things smoother, but maybe not the way I applied it.)
Even adding "move fld 1 relative 0,-1" for each iteration, to compensate for the downward drift, didn't slow it down.
Anyway, as always, I learned some new things here, and the snapshot method is very flexible and good to know.
Thanks guys, you're the best!