This site requires JavaScript, please enable it in your browser!
Greenfoot back
btj9
btj9 wrote ...

2011/10/6

Object Movement

btj9 btj9

2011/10/6

#
I have two objects, one object is larger than the other. The larger object is keyboard controlled while the smaller is randomly moving by the computer/program. When the larger object is requested to move there is hesitation in the automated movement of the smaller object. In Greenfoot, does its environment use some form of parallelism when it allocates the CPU to each act( ) execution to give the impression that all objects move in parallel (at the same time)?
davmac davmac

2011/10/7

#
The act() method for all objects is called in turn. So if you have two actors "a1" and a2" then: a1 acts, then a2 acts, then a1 acts again, then a2 acts again, and so on. It's honestly that simple. With the behaviour you've described, it sounds like it's something else in your code that's causing the smaller object to stop moving. How exactly does the larger object get requested to move?
Duta Duta

2011/10/7

#
This sounds a lot like the crab scenario :p You can always take a look in there and compare it to your code.
btj9 btj9

2011/10/7

#
Thank you davmac, that explains it perfectly! My first actor's, a1, act() is lengthy, including multiple image swaps and directional changes with small wait times. I am new to programming and have decided to learn with Greenfoot. You hear all these ads about Windows machines being able to truly multi-tast so I wasn't sure if both acts were suppose to run simultaneously or if they ran in turn like you've described. Knowing they run in turn tells me it is my code and I'm trying to do too much at once. Also, thank you Duta, it is a lot like the crab scenario. In fact, the crab was my starting point and have grown from that foundation. Thank you to both of you!
You need to login to post a reply.