home *** CD-ROM | disk | FTP | other *** search
- 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
- From: mxmora@unix.SRI.COM (Matt Mora)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Arcade-style animation...
- Message-ID: <43367@unix.SRI.COM>
- Date: 28 Jan 93 19:29:34 GMT
- References: <1993Jan23.014127.5750@cs.ucla.edu>
- Organization: SRI International, Menlo Park, California
- Lines: 90
-
- In article <1993Jan23.014127.5750@cs.ucla.edu> tj@kona.cs.ucla.edu (Tom Johnson) writes:
-
- >
- > foreach sprite
- > CalculateNewLocation()
- > foreach sprite
- > EraseSprite() // by copying the sprites old location from
- > // a bkgnd screen to an offscreen world
- > foreach sprite
- > DrawSprite() // by copying the sprite onto the offscreen
- > // world
- > UpdateScreen() // by copying the offscreen world onto the
- > // screen.
-
- Here's what I found to be pretty fast for a sprite. Since the actual area
- to be erased is quite small after the sprite has moved a few pixels, I
- calculate the rgn that would need updating when I blast the sprite in its new
- position. You don't need to erase the area where the sprite will go because
- the sprite will wipe out what was there. After creating the new mask region,
- I copybits only the background bits that are "uncovered" by the sprites
- new location, then I copybits the sprite to its new location. Below
- is a graphic example.
-
-
- ................................
- ................................ . are background
- ...........xxxxx................
- ...........xxxxx................ X is sprite
- ...........xxxxx................
- ................................
- ................................
- ................................
-
- ................................
- ................................
- ......... ................. Space is the old sprite's
- ........xxxxx ................. location that needs to
- ........xxxxx ................. be updated after the sprite
- ........xxxxx .................. has moved. Only the white space
- ............................... needs to be updated.
- ................................
- ................................
-
-
- Shameless plug:(Ascii Graphics brought to you by Ascii Paint written by me :)
-
- Below is some code that show it in action.
-
- BackWorldPtr is the Background
- picWorldPtr is the sprite's grafport
- wPtr in the game window.
-
- repeat
- .
- .
- .
-
- RectRgn(maskRgn, dRect);
- RectRgn(edgeRgn, olddrect);
- DiffRgn(edgeRgn, maskRgn, maskRgn);
-
- if gTickCount >= LastTick then
- begin
- {copy the area that needs updating}
- CopyBits(GrafPtr(BackWorldPtr)^.portBits, GrafPtr(wPtr)^.portBits,
- olddRect, olddRect, srcCopy, maskRgn);
- {blast the sprite into its new position}
- CopyBits(GrafPtr(picWorldPtr)^.portBits, GrafPtr(wPtr)^.portBits, pRect,
- dRect, srcCopy, nil);
- olddrect := drect;
- LastTick := Tickcount;
- end;
-
- .
- .
- .
- .
- end;
-
- That's one way to do it.
-
-
- Xavier
-
-
- --
- ___________________________________________________________
- Matthew Mora | my Mac Matt_Mora@sri.com
- SRI International | my unix mxmora@unix.sri.com
- ___________________________________________________________
-