Combine two images to make one

01-11-2005, 09:13 AM
This is for a game, but my actual problem is with images an not the game itself, so I'm posting here.
I'm making a game with pieces for the player to move around, and each piece is to have a number displayed on the piece (like in stratego if you're familiar with it). I don't want to put the numbers directly on the image files, but rather load the images into the program, and apply the numbers in run-time so that in a later development the user can add his/her own images to use as game pieces.
However, I don't want to have to move the game piece image AND the numeric image seperately whenever a piece is moved. Is there a way I can combine the two into one image so I can move both with one easy call?

(on a side note, I'm just using image boxes for the game pieces and moving the image boxes around the board. If anyone has a better method, feel free to share :) )

01-11-2005, 11:26 AM
You may want to look into BitBlt and use it with a mask - this technique will allow you to essentially paint shaped images (not just rectangles) so you could paint your numbers on top of your pieces. BitBlt isn't really compatible with image boxes though - consider changing to picture boxes :). However, personally I wouldn't have a separate control for each piece as it may get fairly memory intensive. Instead I'd have one big picture box and paint lots of little pieces inside it in the correct positions. It will be more complicated to code, but will end up being more robust.

01-11-2005, 11:47 AM
I guess I was thinking along the same lines as steRobson when I created this little sample.

PaintPicture is a close cousin to BitBlt, the difference being that it requires a picture object (like from a picturebox)

Putting your 'number images' in one picturebox as a sheet is also good advice.

The quickly made example I'm posting merely shows one technique for making one image out of two.

The PaintPicture method has a lot of optional arguments; I just used the basic stuff.

Hope it helps.


01-11-2005, 12:16 PM
Wow. I guess I had seriously underestimated the use of picture boxes! Just goes to show they really don't teach you much in two semesters of VB at a religeous school. =P
Thank for the code noi_max. It helped a lot. I'll probably have to strip my plans for this program and redo them, but at least I hadn't written any code yet =)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum