Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Nov 21, 2017 4:19 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Simple Sprite Pieces to Move on BoardGame Board?
PostPosted: Sat May 29, 2010 6:53 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
I think I asked this question right after REAL Software had dropped sprite support and nothing had yet appeared to take its place. I'm hoping the situation may have changed by now.

Suppose I want to write a simple chess game where sprite pieces (irregularly-shaped objects) move from square to square on a chessboard. Is there (again) a simple way to do that?

I'm not interested in anything complicated, such as 3D graphics. 2D graphics is fine for my purposes.

Sometime in the past I seem to remember that I needed to create two graphics files for each sprite: the piece itself (king, queen, rook, whatever) and a "mask," but I don't know whether that is still (or again?) relevant.

I see a lot of references on this Games forum to "Open GPL," but I don't know how that fits in with REALbasic or where to begin with the basic beginner stuff. Where do I start?

Advice, anyone?

Barry Traver


Top
 Profile  
Reply with quote  
 Post subject: Re: Simple Sprite Pieces to Move on BoardGame Board?
PostPosted: Sat May 29, 2010 7:59 am 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
I guess a lot depends upon how much animation will be going on.
If you just want to display the pieces, then 'normal' bitmap transparency will do the trick.

Even if you want to do some 'slide from here to here', you will probably get away with it.

The technique can be done two ways:
Mask transparency or 'white' transparency.

With white transparency, you create 6 bitmaps per side (a black set and a white set)
Your white pieces can not be 100% white.. maybe &cf0f0f0 is white enough

The background (the part that should not be drawn on screen) should be pure white.
Drag the bitmap into your RB project, and set the transparency property of the bitmap to 'white'

Draw your board.
Draw your pieces at the right spot using .drawpicture, and only the colored part will be drawn over the board.


Alternatively, if you use a mask approach, you can have partial transparency.
You start with the same image as above.
Then turn all the non-pure white parts into black or some shade of grey.
Thats the mask

Drag both the image and the mask to the RB project, and set the mask property of the original to be the mask image by name.

Again, using drawpicture will get you only the colored parts on screen.

Partial transparency allows for neat techniques such as adding a grey shadow area along the lower edges of the original picture.
Then have the matching area in the Mask be grey instead of black.
The effect of that partial transparency is that when you draw the pieces on a non-simple background (such as textured or marble squares on the chessboard), the underlying texture will be seen 'through' the grey area like a real shadow.

Moving pieces about:
The simplest way is to plot the path from a to b.
Then use a timer to move the piece from point to point along that path until it reaches the destination.

If redrawing the whole chessboard flickers on Windows, do all the drawing into a picture object instead of to a visible canvas.
When the drawing is done, copy the whole picture to a canvas on screen.

_________________
Still RB2009 R5.1
Mac 10.6 + Windows 7/XP + Ubuntu Linux in Vmware
on a Macbook 2.16


Top
 Profile  
Reply with quote  
 Post subject: Re: Simple Sprite Pieces to Move on BoardGame Board?
PostPosted: Sun May 30, 2010 6:14 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
Jeff,

Thanks for the detailed response. I appreciate your taking the time to post it.

Do you know if there any simple sample programs available or any simple source code to move a sprite from point a to point b? I've looked at Buffer.rbp and DragPic.rbp in the examples REAL Software provides, and they are indeed impressive in what they can do, but they are too complex and complicated (at least for me) to figure out exactly what's going on.

I'd be very happy if I had a sample Project that, say, simply moved an object from the left side of the screen to the right when a PushButton control is clicked with the mouse. I would want something that removed the flicker (such as Buffer.rbp does) -- that seems to me rather essential -- but I don't need right now to have the ability to see through the sprites that is shown in DragPic.rbp.

Quote:
I guess a lot depends upon how much animation will be going on.
If you just want to display the pieces, then 'normal' bitmap transparency will do the trick. Even if you want to do some 'slide from here to here', you will probably get away with it.

For now (the chess-type program), I don't need any animation, but I do need to be able to "slide [a piece] from here to there," preferably with no flicker.

Quote:
The technique can be done two ways:
Mask transparency or 'white' transparency.

That comment is helpful, because I was somehow thinking they were the same thing.

Quote:
With white transparency, you create 6 bitmaps per side (a black set and a white set).

Let's see if I've got it now. Technique #1 (white transparency) requires 1 bitmap per piece (black king, black queen, black rook, black bishop, black knight, black pawn, near-white king, near-white queen, near-white rook, near-white bishop, near-white pawn, near-white pawn). Only one bitmap per piece is needed because whatever is white is transparent. Technique #2 (mask transparency) would require (I think) 2 bitmaps per piece (I am not entirely clear on how the 2 would differ from one another, but let's stick with Technique #1, which is all I need right now).

Quote:
Your white pieces cannot be 100% white.. maybe &cf0f0f0 is white enough. The background (the part that should not be drawn on screen) should be pure white.

And that's because if any the pieces were pure white, they too would be transparent (which would not be very helpful, to say the least!).

Quote:
Drag the bitmap into your RB project, and set the transparency property of the bitmap to 'white'

To drag the bitmap into the RB project, I assume I drag the filename from Windows Explorer, but where do I drag it to (i.e., where do I drop the filename I dragged)? Or doesn't it matter?

Quote:
Draw your board.

Now, that much I don't think I'll have much trouble doing!

Quote:
Draw your pieces at the right spot using .drawpicture, and only the colored part will be drawn over the board.

I don't think I've used .drawpicture before, but the Language Reference should tell me what I need to know to do that.

Quote:
Alternatively, if you use a mask approach, you can have partial transparency....

I think I'll work on Technique #1 first and then come back later to Technique #2 if I need it. (Is Technique #2 or something like it used in RB's example program DragPic.rbp?)

Quote:
Moving pieces about:

The simplest way is to plot the path from a to b. Then use a timer to move the piece from point to point along that path until it reaches the destination.

My guess is that the only reason to use a Timer is so that the speed will be the same regardless of the computer on which the Program is run (which would not be true, say, if you used a For/Next loop instead).

Quote:
If redrawing the whole chessboard flickers on Windows, do all the drawing into a picture object instead of to a visible canvas. When the drawing is done, copy the whole picture to a canvas on screen.

Here's where sample code would be helpful, since I have not done any real work with graphics before and don't really know at this point what "do all the drawing into a picture object instead of to a visible canvas" means (although I have the uncomfortable feeling that the word "object" may have some relationship to "object-orienting programming," an area about which I know as little as I know about graphics <sigh>).

Thanks for your patience with me. I'm an "old dog" (next year I'll be "three score and ten") trying to "learn new tricks," so I appreciate your helpfulness.

Barry Traver


Top
 Profile  
Reply with quote  
 Post subject: Re: Simple Sprite Pieces to Move on BoardGame Board?
PostPosted: Sun May 30, 2010 8:27 am 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
Well, theres a lot to take in there, so heres some simplified stuff to get started.
You can drag an image into the project just by dragging from explorer and dropping in the project pane on the left near the windows and menus which are listed.

For this example, Im using 'home made' pieces, and no timers.

Start a new project.
Add to the window a canvas, (Canvas1) and a button.

Add a property called offscreenpic as picture
add a property called pieces(5) as picture

In the window Open event, put this code:

dim x as integer
dim g as Graphics
for x = 0 to 5
pieces(x) = newpicture (32,32,32) //32 pixels is a typical icon size for windows
//all the pieces are blank.. initialised to white
//put something on them
g = pieces(x).Graphics
//random color
g.forecolor = rgb(rnd * 254,rnd * 254,rnd * 254)
g.TextFont = "Courier"
g.TextSize = 40
g.Drawstring chr(x+65),0,32
pieces(x).Transparent = 1 //white is transparent
next
//now we have 6 pieces whch are some color on white
Offscreenpic = newpicture (300,300,32)
//new we have a picture and some pieces.


Add a new method called DrawTheBoard, with a parameter g as graphics
Code:
//we use g as a parameter here because that lets us draw the board onto any graphic.
//it could be straight to screen, onto some picture object, or onto the printer
//for simplicity, I assume the target is our known size of 256 x 256

dim x as integer
dim y as integer
//draw a board
for x = 0 to 7
for y = 0 to 7
if (x+y) mod 2 = 0 then
g.forecolor = &c00ffff
else
g.forecolor = &c308050
end if
g.fillrect x*32,y*32,32,32
next
next


in Canvas1's Paint event put this:
g.drawpicture offscreenpic,0,0


and in the button action event, put this:

dim x as integer
dim del as integer
for x = 32 to 200
drawtheboard Offscreenpic.Graphics
Offscreenpic.Graphics.DrawPicture pieces(0),x,x
Offscreenpic.Graphics.DrawPicture pieces(1), 200 -x,x
//silly little loop to get a delay of sorts.. a timer is probably better, but that comes later
for del = 0 to 10000
next
//make the canvas show the current state of the offscreen picture
canvas1.refresh
next


Run, and press the button.

_________________
Still RB2009 R5.1
Mac 10.6 + Windows 7/XP + Ubuntu Linux in Vmware
on a Macbook 2.16


Top
 Profile  
Reply with quote  
 Post subject: Re: Simple Sprite Pieces to Move on BoardGame Board?
PostPosted: Fri Jun 04, 2010 8:02 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
Jeff,

Thanks for the specific example! Movement does occur when the button is pressed, so my next step is to play with code (making changes here and there) to see if I can figure out what part each part plays (something that a specific example permits but not possible when you have only an abstract discussion).

Barry


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group