Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
on mouseUp
put item 1 of the loc of grc "ramka" into LR
put item 2 of the loc of grc "ramka" into UD
repeat until LR < (- 50)
put 1 into WALKL
repeat until WALKL > 6
set the width of grc "ramka" to the width of img ("L" & WALKL & ".png")
set the height of grc "ramka" to the height of img ("L" & WALKL & ".png")
set the backGroundPattern of grc "ramka" to the ID of img ("L" & WALKL & ".png")
add 1 to WALKL
subtract 10 from LR
move grc "ramka" to LR, UD
wait 20 ticks
end repeat
subtract 10 from LR
move grc "ramka" to LR, UD
end repeat
end mouseUp
AND the blasted thing seems toflashin an extremely annoying way at the end of each inner repeat.
Last edited by richmond62 on Sun Jul 18, 2021 5:45 pm, edited 1 time in total.
richmond62 wrote: Sun Jul 18, 2021 11:24 amAND the blasted thing seems toflashin an extremely annoying way at the end of each inner repeat.
Hi Richmond,
i'm not getting any flashes, but animation is jerky - seems to be a bit smoother if reducing the 'wait' to 10 ticks, but then i don't know much about animating sprites etc. On occasion on opening the stack i get the whole background showing as black.
Would using animationEngine help make this smoother?
on mouseUp
put item 1 of the loc of grc "ramka" into LR
put item 2 of the loc of grc "ramka" into UD
repeat until LR < (- 50)
put 1 into WALKL
repeat until WALKL > 6
set the lockScreen to true -- dunbar
set the width of grc "ramka" to the width of img ("L" & WALKL & ".png")
set the height of grc "ramka" to the height of img ("L" & WALKL & ".png")
set the backGroundPattern of grc "ramka" to the ID of img ("L" & WALKL & ".png")
add 1 to WALKL
subtract 10 from LR
move grc "ramka" to LR, UD
wait 20 ticks
set the lockScreen to false -- dunbar
end repeat
subtract 10 from LR
move grc "ramka" to LR, UD
end repeat
end mouseUp
results in no flashing at all.
Can you explain why?
As you have pointed out, the animation is jerky: but by reducing the size of the lateral movement of the graphic
and the wait period that can be overcome.
[NOTE:] I typed this in before your latest, but here it is anyway.
I don't see screen flashing here. But the movement is indeed pretty jerky due to a couple of things.
First of all, as Craig suggested, locking and unlocking the screen inside the inner repeat loop allows the graphic mangling to take place out of camera range. Secondly, as Stam suggested, the wait statement seems unnecessarily long. Cutting down the wait time helps with this, but I get the best effect by removing the wait completely.
Here's a fairly smooth animation effect without flashing or jerkiness.
on mouseUp
local LR, UD, WALKL
put item 1 of the loc of grc "ramka" into LR
put item 2 of the loc of grc "ramka" into UD
repeat until LR < (- 50)
put 1 into WALKL
repeat until WALKL > 6
lock screen # do this out of sight
set the width of grc "ramka" to the width of img ("L" & WALKL & ".png")
set the height of grc "ramka" to the height of img ("L" & WALKL & ".png")
set the backGroundPattern of grc "ramka" to the ID of img ("L" & WALKL & ".png")
add 1 to WALKL
subtract 10 from LR
move grc "ramka" to LR, UD
unlock screen # now show what's been done
--wait 20 ticks # no
end repeat
subtract 10 from LR
move grc "ramka" to LR, UD
end repeat
end mouseUp
It appears you already have answers to address some of these issues.
One thing I found in animation a few versions ago (not really done anything of the ilk in recent times) which therefore may not be worth mentioning: when moving an object (button/sprite/icon/whatever) the rendering of the "leading edge" seemed to be problematic, with the "original" edge being the "mask" but the "after movement" position being the "trailing edge" so it looks like the front of the object is cut off.
This was remedied by having a little buffer area of transparency around the object, so that only the transparent part gets cut off znd hence not noticeable. It might be a bit relevant, or not.
a little buffer area of transparency around the object
Is that round the images in the sequences used as backGroundPatterns in the graphic or
re the borders of the graphic compared with those images?
The problem is that if one expands the size of the graphic one gets the images repeating (tiling).
-
-
I suppose one could go back and expand the transparent area round each image
(although, when I think about that, I suddenly remember that I have to go and have a bath
so I don't smell like a rank raccoon tomorrow in class - 36 degrees Celsius with 75% humidity
here today) in the sequence.
More for my own interest and as a diversion i played a bit with this - i dislike things running in loops as they can lock the interface.
For example it can be hard to change directions or pause.
An alternative is to recursively call an animation/movement with 'send to me in xx ticks' which doesn't block the interface. By and large i got this to work just fine but very weirdly the sprite slowly wanders upwards in the screen! Not sure why... even if i try to fix it to a line, it still wonders up...
global gStop
local sPhase, sLoc, sDirection
command marchSprite pDirection
local tDir, tStep, tRect, temp
put pDirection into sDirection
if sDirection = "left" then //images named L1-6 and R1-6
put "L" into tDir
else
put "R" into tDir
end if
//sPhase 1->6
add 1 to sPhase
if sPhase > 6 then put 1 into sPhase
lock screen
set the height of graphic "animationRect" to the height of image (tDir & sPhase & ".png")
set the width of graphic "animationRect" to the width of image (tDir & sPhase & ".png")
set the backgroundPattern of graphic "animationRect" to the id of img (tDir & sPhase & ".png")
unlock screen
if not gStop then
put the rect of graphic "animationRect" into tRect
if sDirection = "left" then
if the left of graphic "animationRect" > 20 then
lock screen
add (-1 * field "step") to item 1 of tRect
add (-1 * field "step") to item 3 of tRect
set the rect of graphic "animationRect" of me to tRect
set the botton of graphic "animationRect" of me to the top of graphic "line" //attempt to stop hovering upwards!
unlock screen
else
exit to top
end if
else
put item 3 of the rect of this stack - the width of graphic "animationRect" * 3 into temp
if item 3 of tRect <= temp then
lock screen
add (field "step") to item 1 of tRect
add (field "step") to item 3 of tRect
set the rect of graphic "animationRect" of me to tRect
set the botton of graphic "animationRect" of me to the top of graphic "line"//attempt to stop hovering upwards!
unlock screen
else
exit to top
end if
end if
else
exit to top
end if
send "marchSprite pDirection" to me in field "ticks" ticks
end marchSprite
on escapeKey
put true into gStop //makes animation stop
exit to top
end escapeKey