home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 22383 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  3.4 KB

  1. Path: sparky!uunet!pageworks.com!world!eff!sol.ctr.columbia.edu!emory!europa.eng.gtefsd.com!paladin.american.edu!howland.reston.ans.net!spool.mu.edu!agate!stanford.edu!unix!mxmora
  2. From: mxmora@unix.SRI.COM (Matt Mora)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Arcade-style animation...
  5. Message-ID: <43367@unix.SRI.COM>
  6. Date: 28 Jan 93 19:29:34 GMT
  7. References: <1993Jan23.014127.5750@cs.ucla.edu>
  8. Organization: SRI International, Menlo Park, California
  9. Lines: 90
  10.  
  11. In article <1993Jan23.014127.5750@cs.ucla.edu> tj@kona.cs.ucla.edu (Tom Johnson) writes:
  12.  
  13. >    
  14. >    foreach sprite 
  15. >        CalculateNewLocation()
  16. >    foreach sprite
  17. >        EraseSprite()    // by copying the sprites old location from
  18. >                // a bkgnd screen to an offscreen world
  19. >    foreach sprite
  20. >        DrawSprite()    // by copying the sprite onto the offscreen
  21. >                // world
  22. >    UpdateScreen()        // by copying the offscreen world onto the
  23. >                // screen.    
  24.  
  25. Here's what I found to be pretty fast for a sprite. Since the actual area
  26. to be erased is quite small after the sprite has moved a few pixels, I
  27. calculate the rgn that would need updating when I blast the sprite in its new
  28. position. You don't need to erase the area where the sprite will go because
  29. the sprite will wipe out what was there. After creating the new mask region,
  30. I copybits only the background bits that are "uncovered" by the sprites
  31. new location, then I copybits the sprite to its new location. Below
  32. is a graphic example.
  33.  
  34.                                        
  35.     ................................   
  36.     ................................          . are background 
  37.     ...........xxxxx................        
  38.     ...........xxxxx................          X is sprite
  39.     ...........xxxxx................   
  40.     ................................   
  41.     ................................   
  42.     ................................   
  43.                                        
  44.     ................................   
  45.     ................................   
  46.     .........      .................        Space is the old sprite's
  47.     ........xxxxx  .................        location that needs to
  48.     ........xxxxx  .................        be updated after the sprite
  49.     ........xxxxx ..................        has moved. Only the white space
  50.     ...............................         needs to be updated.
  51.     ................................   
  52.     ................................   
  53.                                        
  54.                                        
  55. Shameless plug:(Ascii Graphics brought to you by Ascii Paint written by me :) 
  56.  
  57. Below is some code that show it in action.
  58.  
  59. BackWorldPtr is the Background
  60. picWorldPtr is the sprite's grafport
  61. wPtr in the game window.
  62.  
  63. repeat
  64.   .
  65.   .
  66.   .
  67.  
  68.   RectRgn(maskRgn, dRect);
  69.   RectRgn(edgeRgn, olddrect);
  70.   DiffRgn(edgeRgn, maskRgn, maskRgn);
  71.  
  72.   if gTickCount >= LastTick then
  73.     begin
  74. {copy the area that needs updating}
  75.      CopyBits(GrafPtr(BackWorldPtr)^.portBits, GrafPtr(wPtr)^.portBits,
  76.                olddRect, olddRect, srcCopy, maskRgn);
  77. {blast the sprite into its new position}
  78.      CopyBits(GrafPtr(picWorldPtr)^.portBits, GrafPtr(wPtr)^.portBits, pRect,
  79.                dRect, srcCopy, nil);
  80.      olddrect := drect;
  81.      LastTick := Tickcount;
  82.     end;
  83.  
  84.     .
  85.     .
  86.     .
  87.     .
  88.    end;
  89.  
  90. That's one way to do it.
  91.  
  92.  
  93. Xavier
  94.  
  95.  
  96. -- 
  97. ___________________________________________________________
  98. Matthew Mora                |   my Mac  Matt_Mora@sri.com
  99. SRI International           |  my unix  mxmora@unix.sri.com
  100. ___________________________________________________________
  101.