Object movement causing lag and jerks, SOLVED

Create fast, sprite powered games with Animation Engine, co-developed with DerBrill Software!

Moderators: heatherlaine, kevinmiller, robinmiller, malte

Post Reply
kwnz
Posts: 14
Joined: Sun Sep 06, 2020 1:25 am

Object movement causing lag and jerks, SOLVED

Post by kwnz » Mon Nov 30, 2020 6:41 pm

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
Last edited by kwnz on Tue Dec 01, 2020 1:46 am, edited 2 times in total.

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Object movement causing lag and jerks,

Post by Klaus » Mon Nov 30, 2020 6:57 pm

We have in fact a special "Animation Engine" sub forum, will move this thread there...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Object movement causing lag and jerks,

Post by dunbarx » Mon Nov 30, 2020 7:24 pm

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
Last edited by dunbarx on Mon Nov 30, 2020 7:30 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Object movement causing lag and jerks,

Post by dunbarx » Mon Nov 30, 2020 7:27 pm

Klaus.

This may well be of interest in the animation engine pane, but I think it belongs more in the Beginners pane.

Craig

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Object movement causing lag and jerks,

Post by Klaus » Mon Nov 30, 2020 7:44 pm

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"

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Object movement causing lag and jerks,

Post by dunbarx » Mon Nov 30, 2020 8:03 pm

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

kwnz
Posts: 14
Joined: Sun Sep 06, 2020 1:25 am

Re: Object movement causing lag and jerks,

Post by kwnz » Mon Nov 30, 2020 9:24 pm

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.
duck thing.jpg
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
Last edited by kwnz on Mon Nov 30, 2020 10:11 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Object movement causing lag and jerks,

Post by dunbarx » Mon Nov 30, 2020 9:46 pm

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.
gunship.livecode.zip
(1.41 KiB) Downloaded 299 times
Crude, I know. It needs enhancement.

Also, please enclose your scripts between the code tags "</>".

Craig

kwnz
Posts: 14
Joined: Sun Sep 06, 2020 1:25 am

Re: Object movement causing lag and jerks,

Post by kwnz » Mon Nov 30, 2020 9:59 pm

Screen Shot 2020-12-01 at 09.58.22.png
What is this? (gunship.livecode)

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Object movement causing lag and jerks,

Post by Klaus » Mon Nov 30, 2020 10:43 pm

Hi kwnz,

here an example of the joys of a REPEAT loop with concatenated object names. :D
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

kwnz
Posts: 14
Joined: Sun Sep 06, 2020 1:25 am

Re: Object movement causing lag and jerks,

Post by kwnz » Tue Dec 01, 2020 1:45 am

Klaus, thank you so much that worked perfectly and I THINK I can almost see how. Will mark as solved.

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Object movement causing lag and jerks, SOLVED

Post by Klaus » Tue Dec 01, 2020 1:38 pm

Hi kwanz,

great! :-)
Feel free to ask, I will happily explain everything in detail to you!


Best

Klaus

Post Reply

Return to “Animation Engine”