RE: Ximage
<[email protected]> 28 Oct 2013 07:06:21 -0700
| Newsgroups | gmane.comp.windows.gui4cli |
|---|---|
| Message-ID | <[email protected]> |
Hi Frans, I wrote this text a while ago. I am currently testing Game Editor which is also a free app. I am sorry I was delayed in sending it to the forum, I don't get much time to go online any more. [email protected] mailto:[email protected] is my personal emailer but I rarely look at it. You would be as well to ask me any other query in this thread, which I may check in about a month. Heres the text, and I hope it helps you... ~~~~~~~~~~~~~~~ frans jigsaw.txt Saturday 01-09-13 00:50 Hi Frans, I was very interested in your game example. Have you considered using a free 2D game compiler, like "Game Editor"? That would simplify your task, as things are set up already in a way, to make it easy to move your 'sprites' about a canvas, and you can assign any of the input devices you have including a joystick. Also once learned, you can make other games for the child to play with. It is not a trivial task in pure Gui4Cli, but you can do it. For the game graphics I would use two window guis. One holds the stock of sprites which is like a stock warehouse of jigsaw pieces in this case. A toolbox style window would suit that purpose. The other window is the screen for the 'playing area'. Then you can drag the 'stock window' to any position that is convenient while you play, so you can also hide that window, and show it etc. I would create a grid of xArea controls, which are invisible to overlay the jigsaw area, then you can detect a click on any of those to 'pick up a piece' you put in the wrong place. If there is to be only one, same puzzle in the stock window, a simple grid of xImages suffices, to hold each piece in a random position. I mean 20 x 10 squares and you divide each of your photographs to fit this grid. Or any numbers of squares you choose of course. There is a jigsaw overlay in the free "Photoscape" app, which app is very useful for making your own cards and calendars, or just arranging images for printing. You will also need an image editor with a good magic wand selector tool and the use of layers. I would use the free Hornil Stylepix for that. You may already have a favourite app. Make an image of the same size as your photograph, with a full white or black background and add the Jigsaw effect. Export it to a file or clipboard, then import into a layer in your editor. The colour will contrast with the jigsaw curves, making the 'piece shapes' easy to select accurately, using the magic wand. Use that shape like a cookie cutter on the photograph, and repeat, until you have saved an array of small rectangular images of pieces. These have a shaped photo section on either white or black in a rectangular or square image. It is maybe best to name the files as 1.bmp,2.bmp,3.bmp... You would need two random numbers to choose where they are placed in the grid of xImages. The script should check if there was already a piece displayed in that xImage. If yes then throw two more random numbers. Keep a count of how many are filled and stop when complete. Once they are placed you can use something like : > Update #this Img2x3 piece11 TRIGGER The images should already be loaded in the xonload event. If they are numbers : >Image LOAD ":1.bmp" piece1 for each piece. You may try doing that in a counting loop to reduce the code. Having loaded the images into each xImage the script should have a record of which piece is in which xImage. When the player clicks the xImage, your code can find which piece ID is attached there. Place a background texture where the xImage was picked and record it in the array so it can not be picked twice. Then the player moves the cursor to the 'Board'. Change the cursor to represent a playing piece on focus that window. Then the location where you click can return to you the top, left of the xArea you click into. That is where you want to draw the image of the piece. If there is a single xImage the same size as the panel in the target board window, you can blit onto an image then update it there. I advise to load a simple graphic into the empty board at the start of play. You can use the Gui4Cli Image commands to blit the rectangular pieces onto the board background. This can be done for all those 'laid so far', then update the xImage from the image in memory. I reckon you will need to detect the background colour of your piece images and use that in the command to get a transparent overlay: Image trim '255/255/255/1/1/1' Unless Dimitris has updated it for Blit with masks, you may be able to do it with trim. You would need to know the width of the hooks and holes. First you write a function that takes the width and height and returns a comma separated [right, bottom] value. Then you will be able to do a simple subtraction to know where to locate the next piece. An alternate method I use is to 'Hover' the cursor on an item to excite it. You can get the event of the xImage that way, hence the piece ID, and the same method ensues. This type of action is much easier to achieve in a game creation app, or something like Flash, or SwishMax, which are built for animation embedded in a web page. Then you can launch the web page in Gui4Cli and control it that way. You have chosen a hard job. I wish you luck. If you have more questions arising from these suggestions, place it in this thread, I dont check my emailer any more. I will log in asap. Regards, Flicknemo