Since the actors are added to the paint-order list when addActor() is called, sprites added later will lie above the others. The order of execution thus determines the visibility of the sprite images: images of later actors cover the ones of all previously drawn actors, they lie above them, so to speak. In the game loop, the images of all Actors are copied into a screen buffer according to the order in the paint-order list and finally rendered in the game window. The drawing of the sprite images happens according to the following principle. Loops and delays have especially catastrophic effects, since other actors must wait for their own call of act(). An internal game loop (in this case also called a simulation cycle) periodically runs through this list and subsequently calls all the actors' specific act() methods due to polymorphism.įor this ingenious principle to work, the actors have to be cooperative, i.e. When adding a character to the game window with addActor(), it will be inserted into an act-order list (ordered by Actor classes). The user-defined derived actors then override act() and thereby implement the specific behavior of the actor. The method act(), defined for the class Actor(), has an empty definition part, and so it returns immediately. JGameGrid uses an animation concept also available in other game libraries, particularly Greenfoot. By default, 60 sprite images are generated for every 6 degrees of rotation. At runtime, the images therefore do not have to be loaded from the hard drive or otherwise transformed, which would decrease the performance. The latter are, at the creation of the Actor object, loaded into an image buffer that also contains the rotated images. In JGameGrid, for efficiency reasons, one has to already specify at their definition whether Actors can be rotated and which sprite images they are assigned. The rotation angle should automatically be adjusted to the direction of the movement. Game tokens also often change their place, direction, and rotation angle. This is simpler than modeling Actors with different sprites via class derivation. For this reason, an Actor object can be assigned any number of different sprite images that are distinguished by an integer index (the sprite ID). However, they get their specific appearance loaded from an image file, called a sprite.Īctors in a game are animated in various ways: they move across the game area and change their appearance in the process, e.g. When working with the game library JGameGrid, all tokens should be derived from the class Actor so that they already include many important features and capabilities without any necessary programming effort.
0 Comments
Leave a Reply. |