Object movement causing lag and jerks, SOLVED
Moderators: heatherlaine, kevinmiller, robinmiller, malte
Object movement causing lag and jerks, SOLVED
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
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
Last edited by kwnz on Tue Dec 01, 2020 1:46 am, edited 2 times in total.
Re: Object movement causing lag and jerks,
We have in fact a special "Animation Engine" sub forum, will move this thread there...
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Object movement causing lag and jerks,
Hi.
You do not need the animation engine. On a new card, make a button. Put this in the button script:
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
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
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
Last edited by dunbarx on Mon Nov 30, 2020 7:30 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Object movement causing lag and jerks,
Klaus.
This may well be of interest in the animation engine pane, but I think it belongs more in the Beginners pane.
Craig
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,
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"
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"
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Object movement causing lag and jerks,
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
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,
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.
Card-
Start-
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
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
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
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
Hope this helps, thanks again.
Hope this helps
------------------------------------------
ADMIN note: Added code tags
Last edited by kwnz on Mon Nov 30, 2020 10:11 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Object movement causing lag and jerks,
Hmmm. Attached is the stack with the handler just as I made it.I did try the script provided by Dunbarx (thank you) it did nothing
Crude, I know. It needs enhancement.
Also, please enclose your scripts between the code tags "</>".
Craig
Re: Object movement causing lag and jerks,
What is this? (gunship.livecode)
Re: Object movement causing lag and jerks,
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:
Best
Klaus
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
Klaus
Re: Object movement causing lag and jerks,
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
Hi kwanz,
great!
Feel free to ask, I will happily explain everything in detail to you!
Best
Klaus
great!
Feel free to ask, I will happily explain everything in detail to you!
Best
Klaus