home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / SpriteWorld 2.2 / Documentation / Add-On Docs / Circular Scrolling < prev    next >
Encoding:
Text File  |  1998-12-06  |  7.6 KB  |  142 lines  |  [TEXT/ttxt]

  1. Circular Scrolling Documentation
  2.  
  3. Since two or three people have requested Circular Scrolling, I finally decided to spend some time working on routines that will enable this, even though I don't plan on using the routines myself (and therefore had little motivation to spend the time required to work on them). Circular scrolling allows you to scroll endlessly in any direction; when you scroll off one end of the world (such as the right end), you come back in the other end (such as the left end).
  4.  
  5. SpriteWorld's circular scrolling engine has the following limitations:
  6.  
  7. • Your virtual world's width and height must be a multiple of your offscreen area's width and height. For instance, if your offscreen area's width is 600, your virtual world can have a width of 600, 1200, 1800, etc. If your offscreen area's height is 500, your virtual world's height can be 500, 1000, 1500, etc.
  8.  
  9. • All of the standard scrolling limitations apply. So the dimensions of your offscreen areas must still be an even multiple of your tile's width and height.
  10.  
  11. • There is currently no way to mix circular scrolling with multiple views. In other words, you're stuck with one view of the world. I could probably change this if there is any interest.
  12.  
  13. • The SWRegionCollision and SWPixelCollision routines will not work when detecting collisions between sprites that are on opposite "edges" of a circular world. They may be overlapping in reality (and visibly on the screen), but these pixel-precise collision detection routines won't detect it. I could also fix this if there is enough interest, but in the mean time, the standard collision detection is accurate enough.
  14.  
  15. • SWCheckSpriteWithTiles will not properly detect collisions with tiles when the sprite is hanging off the edge of the virtual world.
  16.  
  17. • Idle sprites get redrawn every frame if they are visible on screen. (Hint: don't place a huge 640x480 idle sprite in your world!)
  18.  
  19. • SWFlagScrollingRectAsChanged probably won't work correctly if the rect is hanging off the edge of the virtual world, although this hasn't been tested, so I don't know for sure. This can be fixed if needed.
  20.  
  21.  
  22. Getting Started
  23.  
  24. To use Circular Scrolling in your application, you will need to add both Scrolling.c and Circular Scrolling.c to your project. (Circular Scrolling.c is found in the SpriteWorld FIles -> Utils folder.)
  25.  
  26. Performing a Circular Scrolling animation is very similar to how you would perform a normal scrolling animation. The only difference is that you must make the offscreen areas so they multiply evenly into the width and height of your virtual world's boundaries. Additionally, you must call the Circular Scrolling routines listed in the Function Reference below instead of their standard scrolling or tiling equivalents. Also make sure to call SWSetScrollingWorldMoveBounds; this is how SpriteWorld knows the dimensions of your virtual circular world. The top and left sides of your circular world's bounds must be 0.
  27.  
  28. Also, some SpriteWorld functions, such as SWPixelCollision, SWRegionCollision, SWIsPointInSprite, and others may not work correctly when used with sprites that are part of a circular scrolling animation, since those functions are not set up to detect the wrapped parts of a sprite. (That is, the parts hanging off one edge of the world and being wrapped onto another side.)
  29.  
  30. If you use tiling, the requirements are the same as a normal scrolling SpriteWorld: the offscreen area must be evenly divisible by the tile's width and height.
  31.  
  32. Here is a list of the standard scrolling/tiling functions, and the version you should use instead in a circular scrolling animation:
  33.  
  34. SWUpdateSpriteWorld                      -            SWUpdateCircularSpriteWorld
  35. SWProcessSpriteWorld                    -            SWProcessCircularSpriteWorld
  36. SWAnimateSpriteWorld                 -            SWAnimateCircularSpriteWorld
  37. SWMoveVisScrollRect                     -            SWMoveCircularVisScrollRect
  38. SWOffsetVisScrollRect                 -            SWOffsetCircularVisScrollRect
  39. SWCollideSpriteLayer                      -          SWCollideCircularSpriteLayer
  40.  
  41. SWDrawTilesInBackground        -            SWDrawTilesInCircularBackground
  42. SWChangeTileImage                            -            SWChangeCircularTileImage
  43. SWDrawTile                                                    -            SWDrawCircularTile
  44.  
  45.  
  46. Function Reference
  47.  
  48. The funciton reference below assumes a knowledge of the standard scrolling routines. Brief descriptions of the functions are given in many places, since these routines are almost identical to the standard scrolling routines.
  49.  
  50.  
  51. SWProcessCircularSpriteWorld
  52.  
  53. void SWProcessCircularSpriteWorld(
  54.     SpriteWorldPtr spriteWorldP)
  55.  
  56. Call this function to process a circular scrolling animation.
  57.  
  58.  
  59. SWAnimateCircularSpriteWorld
  60.  
  61. void SWAnimateCircularSpriteWorld(
  62.     SpriteWorldPtr spriteWorldP)
  63.  
  64. Call this function to render a circular scrolling animation on the screen.
  65.  
  66.  
  67. SWUpdateCircularSpriteWorld
  68.  
  69. void SWUpdateCircularSpriteWorld(
  70.     SpriteWorldPtr spriteWorldP)
  71.  
  72. Unlike SWUpdateSpriteWorld and SWUpdateScrollingSpriteWorld, it is not necessary to call SWUpdateCircularSpriteWorld before starting your animation. That's because all this function does is copy the background to the work area, and then call SWAnimateCircularSpriteWorld to draw the sprites in the work area and update the screen. So if you don't want to call this function before starting your animation, just make sure you copy the background to the work area first.
  73.  
  74.  
  75. SWUpdateScrollingWindow
  76.  
  77. SW_FUNC void SWUpdateScrollingWindow(
  78.     SpriteWorldPtr spriteWorldP)
  79.  
  80. This function is actually part of Scrolling.c, but it can also be used during a circular scrolling animation to quickly update the screen in response to an update event.
  81.  
  82.  
  83. SWDrawTilesInCircularBackground
  84.  
  85. SW_FUNC OSErr SWDrawTilesInCircularBackground(
  86.     SpriteWorldPtr    spriteWorldP)
  87.  
  88. Call this instead of SWDrawTilesInBackground to draw the tiles in your background if tiling is used. Just make sure your TileMap is large enough to entirely cover your virtual world (as defined by SWSetScrollingWorldMoveBounds), or this function could crash.
  89.  
  90.  
  91. SWChangeCircularTileImage
  92.  
  93. SW_FUNC void SWChangeCircularTileImage(
  94.     SpriteWorldPtr    spriteWorldP,
  95.     short            tileID,
  96.     short            newImage)
  97.  
  98. Call this instead of SWChangeTileImage to animate tiles.
  99.  
  100.  
  101. SWDrawCircularTile
  102.  
  103. SW_FUNC void SWDrawCircularTile(
  104.     SpriteWorldPtr    spriteWorldP,
  105.     short            tileRow,
  106.     short            tileCol,
  107.     short            tileID)
  108.  
  109. Call this instead of SWDrawTile.
  110.  
  111.  
  112. SWMoveCircularVisScrollRect
  113.  
  114. void SWMoveCircularVisScrollRect(
  115.     SpriteWorldPtr    spriteWorldP,
  116.     short            horizPos,
  117.     short            vertPos)
  118.  
  119. This function moves the visScrollRect of a circular scrolling animation. If it is moved past the bounds of a circular scrolling world, the visScrollRect is automatically wrapped to the other side of the world.
  120.  
  121.  
  122. SWOffsetCircularVisScrollRect
  123.  
  124. SW_FUNC void SWOffsetCircularVisScrollRect(
  125.     SpriteWorldPtr    spriteWorldP,
  126.     short            horizOffset,
  127.     short            vertOffset)
  128.  
  129. This will offset the visScrollRect by horizOffset and vertOffset. If the visScrollRect is moved past the bounds of a circular scrolling world, the visScrollRect is automatically wrapped to the other side of the world.
  130.  
  131.  
  132. SWCollideCircularSpriteLayer
  133.  
  134. void SWCollideCircularSpriteLayer(
  135.     SpriteWorldPtr    spriteWorldP,
  136.     SpriteLayerPtr srcSpriteLayerP,
  137.     SpriteLayerPtr dstSpriteLayerP)
  138.  
  139. This function is identical to SWCollideSpriteLayer, except that it works with circular scrolling SpriteWorlds. That is, it properly detects collisions between sprites even when one or both sprites are hanging off the edge of the world (with part of the sprite being wrapped to the other side). So even the wrapped part of a sprite gets checked with the other sprites when the collision detection is performed.
  140.  
  141. When your CollideProc is called, the rect passed to it may be hanging off the edge of the right or bottom side of the circular world. It will never hang off the left or top sides.
  142.