|
Event handling and the Platform Problem Continued...So far I've established why it is difficult to put solid-object handling into a collision event. That leaves three obvious candidates:
The step event looks promising. It occurs before collisions so collisions will be evaluated based on where an object finishes up after collisions with walls have been taken into account. The main problems I see are:
A step event that occurred between positions being updated and collisions being evaluated would be good. At this point friction and gravity have been taken into account. There is one problem:
The end step event is a good time to do solid handling. Both the old and new positions of the object are available, in x, y and xprevious, yprevious. If we set the position of the object back to its previous position we can then evaluate a move by its current hspeed and vspeed to ensure that it stops outside solids. Problems:
Solution:Use the end step eventWe will assume that hspeed and vspeed do not change greatly in collision handling. If necessary we can buffer any changes in direction in two variables hs and vs which would be added to hspeed and vspeed at the end of the end step event. The uncertainty in the location of the object when collisions are evaluated will be tolerable most of the time. |