Page 1 of 1

Oiling the Gears in an App with Lots of Moving Parts

Posted: Thu Feb 02, 2012 3:36 am
by manofarms
I've got a relatively simple graphical drag and drop game that I'm building for practice. It consists of dragging the planets to the correct orbits around the sun. Currently, when the user drags a planet to the correct orbit, the planet (which is a button object) moves along a circular path determined by a free hand curve.

Code: Select all

   if intersect(button thingGrabbed, graphic thingGrabbed, 1) then
      move button thingGrabbed to the points of graphic (thingGrabbed & "hilite") without waiting
      set the icon of button thingGrabbed to (thingGrabbed & "big")
      set the width of button thingGrabbed to the width of img (thingGrabbed & "big")
      set the height of button thingGrabbed to the height of img (thingGrabbed & "big")
      move button thingGrabbed to the loc of img (thingGrabbed & "big") in .5 seconds without waiting
   end if
Then in each button's script is the following code to keep it orbiting:

Code: Select all

 if intersect(me, graphic (the short name of me), 1) then
       move me to the points of graphic ((the short name of me) & "hilite") without waiting
       end if
When I try to move the last planet, the program lags quite a bit. Is there anyway to speed up the processing or eliminate the lag? Will it require a different approach?

Re: Oiling the Gears in an App with Lots of Moving Parts

Posted: Thu Feb 02, 2012 5:53 am
by kdjanz
Just off the top of my head, trying to go back to lesson 3 or 4 where Dave was talking about animation - seems a long time ago now -

In the tutorial Dave said that intersect was relatively processor intensive, so once the player has successfully matched planet and orbit, why not just set a flag for the planet and go into moving it without doing the intersect each time.

Also, in one of the Academy threads, we were told that move is not an efficient way to do animation. The best way is to set the loc of the planet button to the next set of points on the orbit graphic, so it bumps along a node per frame. If that is too fast, you can set the code to just move it every 4th frame or 10th frame for whatever looks good. You want to minimize the computation done within the game loop.

You also need to remember to set the planet buttons to dynamic so that they get the benefit of the new engine as well.

Reviewing those lessons might help you with the mechanics...


Re: Oiling the Gears in an App with Lots of Moving Parts

Posted: Tue Feb 07, 2012 2:11 pm
by manofarms
Alright, I've changed a lot of the inner workings. I am only using an intersect once to check and see if the planet is over the right orbit when the mouse is let go. I got rid of the move commands and am using set locations in a nifty little "send with messages" loop. I still am having some lag though. I couldn't find the particular lessons you were referring to, could you please post a link? I would love to get this figured out, because I've been puzzling over it for hours.

Re: Oiling the Gears in an App with Lots of Moving Parts

Posted: Fri Aug 31, 2012 7:36 am
by Surbhit29
Can you please tell me the lessons given by Malte on animation. I am finding it difficult to search them.
Please send me the link of those lessons.