This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-08-21 10:35:46

gtoal
Scratcher
Registered: 2010-08-15
Posts: 26

Avoiding the delay between frames

I learned yesterday that the frame synch happens at the end of every loop, regardless of whether it is the main controlling loop, or just some iterative code that calculates something incidental.  So I seriously restructed my code so that there's one main loop, and it sends a 'NEXTFRAME' message to every sprite, which the sprites wait for and act on by executing straight line code, rather than any looping.

It works pretty well, except for one unavoidable? problem.

The navigation of the maze in my pacman derivative works by having a layer that is aligned with the maze, where a 1-pixel-wide line is drawn down the center of every path that the actors can traverse.  The characters themselves are arbitrary sprites superimposed on the real sprite that does the business - a 1x1 single pixel that starts life placed on one of these center lines.  My doing a 'touching' test, that pixel can determine the junctions in the maze etc with no need to care about walls for example.

The problem lies in getting the speed above one pixel per frame.  If I move several pixels at a time, I can fall off the end of a line, so I get around this by having my move code move one pixel at a time but being able to do more than one 1-pixel move per frame.

Therefore instead of doing this in a loop - which forced a frame delay on each iteration, I had to do it by cut & pasting the 1-pixel move code multiple times so that there were no loops involved.  This took a clean structure and made it very messy, setting a bad programming example.

So bottom line, is there a way to repeat a group of instructions without simply duplicating them, or causing a frame delay?

Thanks

Graham

Offline

 

Board footer