Page 1 of 1
Object movement causing lag and jerks, SOLVED
Posted: Mon Nov 30, 2020 6:41 pm
by kwnz
Not sure where to post this ( Mac, Games, Animation Engine etc, feel free to move it if necessary.
Hi guys, Could someone help an old guy suffering from synapse fatigue to get this working smoothly while the player plays the game. The player would move a Gun horizontally with “grab” while shooting Ducks with the spacebar. Having made a selection of solitaire card games on my Mac mini for various nephews, I have always used very basic commands in the scripts mainly to enable the kids to see how they could make their own games but partly to save my ailing synapses. For this I did not even want to use Animation Engine but could not see any other way, however it has proven to be way over my ancient head. I suspect the “repeat” command is wrong and maybe use “send in time” which completely baffles me as how to write it let alone incorporate it here.
Thank in advance for any help, please bear in mind I may not understand what the hell you’re talking about…
on mouseup
repeat until line 7 of field "deadducks" > "5"
aeMoveTo the long ID of img 1,(700,259),2000,"overshoot"
aeMoveTo the long ID of img 2,(700,259),3000,"overshoot"
aeMoveTo the long ID of img 3,(700,259),5000,"overshoot"
aeMoveTo the long ID of img 4,(700,259),7000,"overshoot"
aeMoveTo the long ID of img 5,(700,259),9000,"overshoot"
aeMoveTo the long ID of img 6,(700,259),11000,"overshoot"
wait 4 sec with messages
aeMoveTo the long ID of img 1,(36,260),0,"inOut"
aeMoveTo the long ID of img 2,(36,260),0,"inOut"
aeMoveTo the long ID of img 3,(36,260),0,"inOut"
aeMoveTo the long ID of img 4,(36,260),0,"inOut"
aeMoveTo the long ID of img 5,(36,260),0,"inOut"
aeMoveTo the long ID of img 6,(36,260),0,"inOut"
wait 1 sec with messages
end repeat
end mouseup
Re: Object movement causing lag and jerks,
Posted: Mon Nov 30, 2020 6:57 pm
by Klaus
We have in fact a special "Animation Engine" sub forum, will move this thread there...
Re: Object movement causing lag and jerks,
Posted: Mon Nov 30, 2020 7:24 pm
by dunbarx
Hi.
You do not need the animation engine. On a new card, make a button. Put this in the button script:
Code: Select all
on mouseDown
grab me
end mouseDown
on rawkeyDown tKey
if tkey = 32 then
create grc
set the loc of last grc to the mouseLoc
set the width of last grc to 40
set the height of last grc to 10
moveGraphic
end if
end rawkeyDown
on moveGraphic
repeat 100
set the left of last grc to the left of last grc + 5
wait 1 with messages
end repeat
end moveGraphic
Grab the button and move it up and down near the left side of the card. Hit the spaceBar now and then.
Now this can SURELY use refinement. Write back if you need help with this. For example, instead of using the spacebar, why not use the arrowkeys, so that you can shoot in four directions? That sort of thing...
Craig
Re: Object movement causing lag and jerks,
Posted: Mon Nov 30, 2020 7:27 pm
by dunbarx
Klaus.
This may well be of interest in the animation engine pane, but I think it belongs more in the Beginners pane.
Craig
Re: Object movement causing lag and jerks,
Posted: Mon Nov 30, 2020 7:44 pm
by Klaus
As you can see, the forum leaves "shadow topic" in place after moving a thread.
Maybe that is sufficient?
If not, I can move this thread back to the beginners section.
However this IS in fact an animation engine question, isn't it?
-> aeMoveTo the long ID of img 1,(700,259),2000,"overshoot"
Re: Object movement causing lag and jerks,
Posted: Mon Nov 30, 2020 8:03 pm
by dunbarx
Klaus.
Not sure what the OP intends, but having both available is the best.
@kwnz.
Are you set on the animation engine, or just thought that was a good way forward? My solution stays "inside" LiveCode and may require more direct coding than the AE, which may have greater functionality, but that is all up to you.
Craig
Re: Object movement causing lag and jerks,
Posted: Mon Nov 30, 2020 9:24 pm
by kwnz
Gosh such quick responses! Well I really don't care how this is done but your ideas seem much simpler. I did try the script provided by Dunbarx (thank you) it did nothing (my fault somehow I am sure). I thought a screenshot would be helpful along with my very messy scripts I have done so far. On reflection this appears rude I certainly do not expect you to recode the whole thing but merely to give a better understanding of my intent.
Stack-
Code: Select all
on openStack
if "animationEngine" is not among the lines of the stacksInUse then
start using stack "animationEngine"
end if
end openStack
Code: Select all
on mouseDown
grab group "groupgun"
end mousedown
Code: Select all
on mousemove
set bottom of group "groupgun" to 498
if intersect (group "groupgun", graphic "rightstop") then
set the right of group "groupgun" to the right of img "ducksbg" - 2 else
if intersect (group "groupgun", graphic "leftstop") then
set the left of group "groupgun" to the left of img "ducksbg"
end if
end if
end mousemove
Card-
Code: Select all
on keydown thekey
if thekey is space then
play gunshot
if intersect (graphic "gunpath", img "duck1") then
play quack
put "duck1" into line 1 of field "deadducks"
set loc of img "duck1" to loc of graphic "duckpen"
add "1" to line 7 of field "deadducks"
end if
if thekey is space then
play gunshot
if intersect (graphic "gunpath", img "duck2") then
play quack
put "duck2" into line 2 of field "deadducks"
set loc of img "duck2" to loc of graphic "duckpen"
add "1" to line 7 of field "deadducks"
end if
if thekey is space then
play gunshot
if intersect (graphic "gunpath", img "duck3") then
play quack
put "duck3" into line 3 of field "deadducks"
set loc of img "duck3" to loc of graphic "duckpen"
add "1" to line 7 of field "deadducks"
end if
if thekey is space then
play gunshot
if intersect (graphic "gunpath", img "duck4") then
play quack
put "duck4" into line 4 of field "deadducks"
set loc of img "duck4" to loc of graphic "duckpen"
add "1" to line 7 of field "deadducks"
end if
if thekey is space then
play gunshot
if intersect (graphic "gunpath", img "duck5") then
play quack
put "duck5" into line 5 of field "deadducks"
set loc of img "duck5" to loc of graphic "duckpen"
add "1" to line 7 of field "deadducks"
end if
if thekey is space then
play gunshot
if intersect (graphic "gunpath", img "duck6") then
play quack
put "duck6" into line 6 of field "deadducks"
set loc of img "duck6" to loc of graphic "duckpen"
add "1" to line 7 of field "deadducks"
end if
end if
end if
end if
end if
end if
end if
end keyDown
Start-
Code: Select all
on mouseup
set loc of img "duck1" to loc of graphic "duckpen"
set loc of img "duck2" to loc of graphic "duckpen"
set loc of img "duck3" to loc of graphic "duckpen"
set loc of img "duck4" to loc of graphic "duckpen"
set loc of img "duck5" to loc of graphic "duckpen"
set loc of img "duck6" to loc of graphic "duckpen"
send mouseup to button "moveall"
end mouseup
The ducks move left to right. The gun is moved either left or right.
Hope this helps, thanks again.
Hope this helps
------------------------------------------
ADMIN note: Added code tags
Re: Object movement causing lag and jerks,
Posted: Mon Nov 30, 2020 9:46 pm
by dunbarx
I did try the script provided by Dunbarx (thank you) it did nothing
Hmmm. Attached is the stack with the handler just as I made it.
Crude, I know. It needs enhancement.
Also, please enclose your scripts between the code tags "</>".
Craig
Re: Object movement causing lag and jerks,
Posted: Mon Nov 30, 2020 9:59 pm
by kwnz
What is this? (gunship.livecode)
Re: Object movement causing lag and jerks,
Posted: Mon Nov 30, 2020 10:43 pm
by Klaus
Hi kwnz,
here an example of the joys of a REPEAT loop with concatenated object names.
It is a bit shorter than your keydown handler:
Code: Select all
on keydown thekey
## Avoid gazillions of IF END IFs :-)
if thekey <> SPACE then
exit keydown
end if
# tKey IS space so:
play "gunshot"
## Now check if any duck intersects:
repeat with i = 1 to 6
put "duck" & i into tCurrentDuck
if intersect (graphic "gunpath", img tCurrentDuck) then
## Always use quotes with object (and audio-/videoclip) names
play "quack"
put tCurrentDuck into line 1 of field "deadducks"
set loc of img tCurrentDuck to the loc of graphic "duckpen"
add 1 to line 7 of field "deadducks"
## Found the duck that intersects, so we can leave the KEYDOWN handler but
## I'm not sure if this is intended, so comment out the next line if neccessary:
exit keydown
end if
end repeat
end keyDown
Best
Klaus
Re: Object movement causing lag and jerks,
Posted: Tue Dec 01, 2020 1:45 am
by kwnz
Klaus, thank you so much that worked perfectly and I THINK I can almost see how. Will mark as solved.
Re: Object movement causing lag and jerks, SOLVED
Posted: Tue Dec 01, 2020 1:38 pm
by Klaus
Hi kwanz,
great!
Feel free to ask, I will happily explain everything in detail to you!
Best
Klaus