Real Software Forums

Need Help with (2D) Sprites
Page 1 of 2

Author:  barrytraver [ Tue May 12, 2009 7:29 am ]
Post subject:  Need Help with (2D) Sprites

I'm trying to figure out how to port over some board-game-type games that I wrote for another computer (the Texas Instruments TI-99/4A, if you're curious). (Many of the games were published in a magazine called MICROpendium perhaps thirty or so years ago.) The kind of thing I have in mind involves (2D) game-pieces that can move from one place to another on the gameboard.

In TI Extended BASIC there was a CALL SPRITE command that made the process simple to do. The "sprite" was much like an object in OOP, an object that had shape, colors, location, speed, etc. as attributes or properties.

What I'd need today would probably involve not only a "sprite," but a "mask" for the sprite, so that the sprite can have an irregular outside shape.

How would something like this be done in REALbasic? The only reference I found in the RB Language Reference to sprites was to "SpriteSurface" in a single entry called "Deprecated Items."

Here's an example of what I'm after: Suppose I wanted to do a chess game. Also suppose that I have appropriate (but rectangular) .jpeg files as needed (for king, queen, rook, bishop, knight, pawn, etc.). Where do I go from there?

Having a specific example would be especially helpful. As Seneca says, Longum iter est per præcepta, breve et efficax per exempla ("The road to learning by precept is long, but by example short and effective").

Thanks in advance for any help you may be able to provide.

Barry Traver

Author:  classone [ Tue May 12, 2009 8:14 am ]
Post subject:  Re: Need Help with (2D) Sprites

The only reference I found in the RB Language Reference to sprites was to "SpriteSurface" in a single entry called "Deprecated Items."

There was your clue as to how much help RB is going to be to your endeavor.
RS now recommends using the 3rd party class SuperSpriteSurface by TinRocket. You can find it at any of the usual places. It is in the process of being updated to assume its new role as the only path to sprite animation for RB. IIRC, It comes with examples

Author:  barrytraver [ Tue May 12, 2009 9:44 am ]
Post subject:  Re: Need Help with (2D) Sprites

Thanks, Roger, for the comments.

You say, SuperSpriteSurface "is in the process of being updated."

Similarly, TinRocket's Web site says, "We [are] working to put tog[e]ther a 'quick start' guide as well as a general overview of how to use SuperSpriteSurface. In the meantime, SuperSpriteSurface includes several detailed & commented demos, as well as the complete API reference. That is, "in the meantime" the "quick start" guide and "general overview are absent?

The "being updated" (note the gerund) and the "working to put together" (again note the gerund) seem to indicate that if I purchase SuperSpriteSurface now ($29.95), I will NOT get the "quick start" guide or the "general overview" or, for that matter, a fully updated version of the program."

Do I interpret the situation correctly? If so, does this mean that I should postpone buying the product until these things have been completed?

Another fact seems even more to make it NOT an option for me at the present time. On their Web site, TinRocket also says this: "Windows and Linux are not yet supported, as are not Mach-O builds on OS X."

I primarily program in Windows (although I'm trying to add Linux to my repertoire), but what good is SuperSpriteSurface for me now if "Windows and Linux are not yet supported"?

If REAL Software is no longer supporting SpriteSurface and TinRocket seems not to be supporting SuperSpriteSurface for Windows, Linux, or the Mac ("Windows and Linux are not yet supported, as are not Mach-O builds on OS X"), should I even try to do games in REALbasic? In all fairness to TinRocket, they do say, "with a little extra work ... , a Windows version of SSS could [emphasis mine] be just around the corner. Well, "around the corner" is not now, nor is "could" the same as "is."

DarkBASIC ($39.95) offers the following 2D support for Windows games:

10 Image Formats Supported
Super-Fast 2D blitting
Mirror, Stretch, Blur and Fade
Screen-Sized sprites
Fast Collision
Animated Sprites
Gamma Control
Scale Sprites
2D Drawing Functions

(It offers 3D support as well, but right now I only need to be able to do 2D sprites.) And, according to the DarkBASIC Web site, "All games created with DarkBASIC are license and royalty FREE" and "All games can be distributed as a stand alone executable," so I would have (as with REALbasic) no difficulty or expense in sharing my programs with others.

Any advice?

Barry Traver

Author:  Steve Garman [ Tue May 12, 2009 9:58 am ]
Post subject:  Re: Need Help with (2D) Sprites

barrytraver wrote:
Any advice?

Take a look at and follow the Beta 2 "More..." link.

Author:  classone [ Tue May 12, 2009 11:09 am ]
Post subject:  Re: Need Help with (2D) Sprites


Author:  Agent [ Wed May 13, 2009 4:19 am ]
Post subject:  Re: Need Help with (2D) Sprites

Also, check out:

which is a replacement for the old SpriteSurface but powered by OpenGL.

Author:  barrytraver [ Wed May 13, 2009 7:36 am ]
Post subject:  Re: Need Help with (2D) Sprites

I "took a look," as Steve Garman suggested, and the Beta 2 "more" link took me to a August 2008 post which mentioned that "The documentation is still incomplete for this beta release."

It does claim that in the Beta 2 release "All features are complete, with the exception of the SuperSpriteSurface.PixelZoom functionality" amd that the Beta 2 release is "compatible with the latest version of REALbasic" (presumably the latest release in August 2008), but I'm not sure what that means. Can Steve (or anyone else with the answer) help me with that?

Specifically, will SuperSpriteSurface now work with Windows? With Linux? With OS X for the Mac?

The Beta 2 "More" post says a lot about text, fonts, and an "OS X utility, 'Font Texture Map,' " but I'm not really interested in typefaces; I'm interested in writing a game in REALbasic (or, if necessary, a logical alternative) that will include sprites (2D is fine; I don't even need 3D). Is that a lot to ask?

My preference, obviously, is to use REALbasic. Since 99% of the time I do my programming in and for Windows (although I almost always open the source code to the public so that others can try it on other platforms, if they so desire), I need something that will work in Windows.

Because the program doesn't use sprites, I did port over my Tic-Tac-Toe Philadelphia Style game program/magic trick to REALbasic, but most of the games I wrote (and, for that matter, puzzle programs, including a version of Jump-a-Peg) are board-type games with moving pieces (hence the need for sprites).

Needless to say, it is surprising, disappointing, frustrating, etc. to me that I am having difficulty doing with REALbasic something that was very simple to do in TI Extended BASIC for the TI-99/4A thirty or so years ago.

Here's what the description of this forum says:

"Wondering how the SpriteSurface is used? ... Look no further, you can ask all your game-related questions here.
Moderators: Jason, User Moderators"

But according to the most recent REALbasic Language Reference:

"Items that have already been removed from REALbasic have no hyperlinks in the following table."

In that table, "SpriteSurface" has no hyperlink; thus it is one of the "items that have already been removed."

The number of "Views" in the Games forum *(1000 or more for some topics) indicates that I am not the only person interested in using REALbasic for games. Do any of you use 2D sprites? If so how?

Barry Traver

P.S. I haven't yet processed the posts from "Agent" and "classone." I hope to do that later today (D.V.). Hopefully, those posts will contain some encouragement for me.

Author:  classone [ Wed May 13, 2009 12:24 pm ]
Post subject:  Re: Need Help with (2D) Sprites

Do any of you use 2D sprites? If so how?

I did before the SpriteSurface was removed from RB. Awhile back I tried SuperSpriteSurface and it was quite buggy. [disclaimer] haven't tried it recently.
I do remember that John B. indicated that SSS was going to go open source in its new role as the only SpriteSurface for RB, and that may be why there seems to be slow development of it; no longer a priority.
I also remember asking the same question above when I found out that SS was to be removed from RB, and finding that there was just no a lot of interest.
I guess that RS has determined that this type of game development is not a priority with RB users.

Author:  oddchild [ Thu May 14, 2009 4:17 am ]
Post subject:  Re: Need Help with (2D) Sprites

Barry I feel your pain. I recently got realbasic. I decided to get it since I wanted a way to make programs (and games) on multiple platforms. It is sad that they got rid of the sprite support. :(

There are other alternatives, but that would require more purchases and going to other languages. Blitzmax also supports windows and Linux, so does Purebasic. Both of them have sprite support... Darkbasic wouldn't allow you to compile into Linux.

On Windows there is a free compiler called brutus2d that is quite fun. :)

Author:  tcIgnatius [ Thu May 14, 2009 12:26 pm ]
Post subject:  Re: Need Help with (2D) Sprites

I use the SuperSpriteSurface, and it works on Windows and MacOS X. :D

Author:  barrytraver [ Sat May 16, 2009 3:26 pm ]
Post subject:  Re: Need Help with (2D) Sprites

Roger Clary,
I do remember that John B. indicated that SSS was going to go open source in its new role as the only SpriteSurface for RB, and that may be why there seems to be slow development of it; no longer a priority.
From what "Agent" posted, it would appear that SuperSpriteSurface is NOT now "the only SpriteSurface for Rb," unless I'm misunderstanding something.

Here's what Charcoal Design says about their RBGLSprites and RBGL3D:
The RBGLSprites module is a complete re-implementation of the REALbasic SpriteSurface using the RBGL classes as a base. Like the RBGLCanvas and RBGLGraphics classes, RBGLSpriteSurface is designed to mimic the behaviour of the existing control. Includes examples.

The RBGL3D library is a re-implementation of the deprecated REALbasic RB3DSpace control. RBGL3D is still in the early stages, but eventually we hope to replicate all the original RB3DSpace functionality.

So which is better, Joe B.'s SuperSpriteSurface or Charcoal Design's RBGLSprites? Is anyone here using either or both? If so, care to comment?

Barry Traver

Author:  barrytraver [ Sat May 16, 2009 3:35 pm ]
Post subject:  Re: Need Help with (2D) Sprites

Thanks for the suggestions for alternatives (BlitzMax, Purebasic, DarkBASIC, Brutus2D, etc.). My preference is to stay with REALbasic, but until there's adequate support again for sprites in REALbasic (or with an RB add-on), I may have to do something else temporarily.

By the way, with the thousands of routines offered by Monkey Bread Software, I'm surprised that MBS does not offer sprite support, particularly when REAL Software is no longer doing so.

Barry Traver

Author:  mojiferous [ Sun May 17, 2009 6:00 pm ]
Post subject:  Re: Need Help with (2D) Sprites

It almost sounds like a sprite surface would be overkill for what you're trying to do- Sprites are nice if you don't want to roll your own collision classes, but in terms of real-world functionality I've always found them a little lacking in terms of modern graphical goodness.

You may want to consider just using a canvas class- it already has all of your needs built-in: graphics, click handling, ease of deployment. Simply add your graphics to the IDE (along with your masks if you're using jpgs) and paint them onto the canvas using the graphics.drawPicture method (actually, paint everything to an offscreen buffer picture and then draw the pieces and parts to the canvas as needed) This also allows you to easily add localizable text using drawString and basic 2d shapes with drawLine, fillRect, etc. As long as you know the geometry of your board you can determine how and where your "sprites" are by keeping track of their coordinates and doing logical testing at the end of "turns" or at preset intervals using a timer class. With board games (at least most board games) the functions behind this would be much easier to employ yourself using arrays and logic based on the known grid (whether square, hex or triangular)... Sprite classes would only help if you've built something that doesn't follow a rigid spatial index. This would be a lot easier, and less prone to deprecation or future crashes than using a sprite class for what you're doing.

Author:  barrytraver [ Mon May 18, 2009 5:12 am ]
Post subject:  Re: Need Help with (2D) Sprites


What you say is VERY encouraging. I am really interested in something very simple (e.g., moving chess pieces on a chessboard); there's no need even for "collision-checking," much less anything more complex.

Question: Is there any chance of a specific example? I find that I learn best when I have a concrete example of RB source code in front of me. If I have an example that I can modify, I don't even have to understand (fully) what I'm doing to accomplish my task! <grin>

I checked the User's Guide for "canvas" and for "mask," but I either didn't find anything relevant ("mask" was primarily used to refer to text masks, not graphics masks) or I didn't find anything that I had the background to understand at this point (e.g., my eyes began to glaze over when I started working through the section on how the "Paint" event handler works).

I know that the Canvas control can have different shapes (e.g., oval rather than rectangular), but I don't know how to use it (if possible) for really irregular shapes (e.g., the outside outline of the knight piece in chess). (And, of course, the canvas control would have to be transparent outside the knight piece.)

By the way, it isn't really necessary (feel free to forget I even said it), but for one of the games I'm porting over it would be nice (but not necessary) for the moving sprite to be animated.

But my key need at the moment is a specific example of RB code illustrating the use of the canvas control to move a piece with an irregular outside outline. (For that situation, I would assume a graphics mask would be necessary.)

Barry Traver

Author:  jefftullin [ Mon May 18, 2009 5:43 am ]
Post subject:  Re: Need Help with (2D) Sprites

My 2p:

I think perhaps this is being overcomplicated.
Let's think chess.

We have a board, which is a static background.
A piece is an irregular shape bitmap.

In RB, this is easily achieved by adding a square bitmap (same size as your chessboard square) with a white background and the piece shown in non-pure-white colours.
For this example, lets imagine the bitmap is a Black Knight, and we call the bitmap BlackKnight

Drag BlackKnight into the project, and set it's transparency property to White
For more flexibility, you can create a mask bitmap, which sets the transparency on a greyscale, allowing semi-transparency if you like.

Simplest method of display:
have a window
In the paint event, paint the board, then use
g.drawpicture Blackknight, row*squaresize,col * squaresize

Repeat for other pieces.

Now, we could extend this to create a 'Piece' class.
The Piece class might have these properties:

row as integer
col as integer
taken as boolean
sprite as picture

To create a Black Knight piece, you could

dim bk1 as new Piece
bk1.row = 1
bk1.col = 0
bk1.sprite = BlackKnight
bk1.taken = false

Now, create a collection or array, to hold the pieces you create.

MyPieces(0) = bk1
or MyPieces.add bk1

Now your board drawing code goes:

//Draw the board as before
//now add all visible pieces
For x = 0 to 63

thispiece = MyPieces(x)
if thispiece.taken = false then
g.drawpicture thispiece.sprite, thispiece.row * squaresize,thispiece.col * squaresize
end if

So this gets you an easy to amend static display.

Animating a move is a little trickier, as you need to do this drawing process (n) times with the piece that is being moved in intermediary places.

So you
create a picture offscreen, draw to it, copy the finalised graphic to the display
Move the piece a little, draw offscreen, copy when complete
repeat until the move is finished.

Page 1 of 2 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group