How do I mirror a 2D image?
Blitz3D Forums/Blitz3D Beginners Area/How do I mirror a 2D image?
| ||
Greetings, Mortals. I, the Mighty WERDNA, am somewhat clueless as to how to mirror a 2D image in game. I.e flip the image from facing right, to facing left. I know this can very easily be done in most paint programs, but I want a way to do it while the player is playing the game. And I know that I could just have two images of the player character, one facing left, and one facing right, and just switch between them, but for this particular program, its not really an option. So... Are there any commands that can do this for me? ;Example of what I want done In game. Players facing right, ![]() Image is mirrored, and player is now facing left. ![]() And just to make sure that you mortals help me out on this, I will give you a bit of incentive. As soon as this is done, and a few other minor things, the first version of the P.U.K.I game engine will be ready for download. Thanks! The Mighty WERDNA(Lord Of Darkness) ![]() |
| ||
http://blitzmax.com/codearcs/codearcs.php?code=1452 |
| ||
What does P.U.K.I stand for? |
| ||
What does P.U.K.I stand for? Everything that's wrong in the world. :) |
| ||
LOL. I was hoping someone would ask that question. P.U.K.I stands for Platformer Unlimited Devolopers Kit. ;Alright maybe PUDK would have been a better acronym, but Puki is the person who 'Inspired' me to make this game engine. Thanks Beaker! this looks like what I need. The P.U.K.I game engine should be ready for me to upload to http://hosted.filefront.com/werdnaworld in just a few days! ;Like maybe 1 if I'm lucky. I hope you like it! |
| ||
http://www.blitzbasic.com/b3ddocs/command.php?name=ScaleImage&ref=2d_cat Use this command to rescale an image to a new size using a floating point percentage (1.0 = 100%, 2.0 = 200%, etc). Using a negative value perform image flipping. |
| ||
If using in game, your best mirroring the image in paint, and having seperate image frames for the flipped character. The quickest way in blitz of flipping is to use copyrect command and copy one line at a time, and place it opposite the area copied. |
| ||
Change it to WALNUT game engine if puki is your inspiration. |
| ||
LOL, the WALNUT game engine is certainly tempting. I tried the first link, given to me by Beaker, and it works just fine for flipping non animation images, but when I try to flip my animated image, it doesn't work so well. This could just be something that I'm doing wrong, so I shall experiment. The second example I have yet to try, although it certainly looks promising. And I agree with you Ross C, but mirroring the image before hand is not really an option for my game engine. Because for this game engine, the player is given the option of drawing their own image for the character, and I don't want them to have to bother flipping the image in their paint program. I want the game to just take care of it for them. Thanks a lot everyone for being so helpful! The Mighty WALNUT ![]() |
| ||
@ WERDNA... Well, here's how I would do it. I hope it helps. Here's the Horzontal version. And here's the Vertical version. |
| ||
Here's some "Walnut Flip" examples, to show the function working.;Flip Image Horizontal Example. Graphics 800,600 Global image = LoadImage("Walnut.png") image = FlipImageHorizontal(image) DrawImage image, 0, 0 SaveImage(image, "WalnutFlip1.png") WaitKey() End Function FlipImageHorizontal(image) temp = CreateImage(ImageWidth(image), ImageHeight(image)) y = 0 For x = 0 To ImageWidth(image) - 1 CopyRect x, y, 1, ImageHeight(image), ImageWidth(temp) - 1 - x, y, ImageBuffer(image), ImageBuffer(temp) Next Return temp End Function ;Flip Image Vertical Example. Graphics 800,600 Global image = LoadImage("Walnut.png") image = FlipImageVertical(image) DrawImage image, 0, 0 SaveImage(image, "WaluntFlip2.png") WaitKey() End Function FlipImageVertical(image) temp = CreateImage(ImageWidth(image), ImageHeight(image)) x = 0 For y = 0 To ImageHeight(image) - 1 CopyRect x, y, ImageWidth(image), 1, x, ImageHeight(temp) - 1 - y, ImageBuffer(image), ImageBuffer(temp) Next Return temp End Function ![]() ![]() ![]() |
| ||
Remember an animated image, is really a long image strip. So to flip it, i believe you'd either have to, draw the image frame onto a hidden image first, then flip that frame. I seem to have a gap in my knowledge of animated images. I'm not sure whether you have to select a frame before altering it, or whether you treat it as just one big image. If it's the latter, you will need to do the same type of thing steve suggested, except move the start point forward the width of a frame each time you flip, so you flip every frame. |
| ||
Major thanks everyone for you help :) As soon as I implement this into my game engine, It will be ready for download. The P.U.K.I game engine(Platformer Unlimited Kinetic Integrator) Will let even a non programmer easily create their very own platformer game! The first version that will be ready for upload shortly will not include the ability to add enemys to your game, or items, but will mainly just concentrate on letting you create the actual levels for your platformer game. Following versions will include these features and several more, and I think that everyone will thouroughly enjoy my game engine. Thanks again for your help! The Mighty WALNUT ![]() |
| ||
Just posting to let you know, that out of all the ways that you guys have listed to mirror an image, the one that worked the very best, was the ScaleImage command. Simply scale the image that you want mirrored,(even an animated image) Give it a negative X value, and the image will be flipped! ;Example ScaleImage WalnutImage,-1.0,1.0 And thats it! This flips the image just fine. So major thanks to everyone who posted, and the P.U.K.I game engine is Nearly ready for download! The Mighty WALNUT ![]() |
| ||
Ere, WERDNA !... Which version number of Blitz3D are you using ?. That ScaleImage image, -1.0, 1.0 don't seem to work on mine. That's why I coded those functions originally. I'm using version 1.99. |
| ||
An please tell me that's not your sig image? If it is, it's way bigger than the forums rules allow, so please chop it down :o) |
| ||
I don't think it's his signature image, Ross, because his older sigs haven't changed; Blitz forum sigs are retroactive, not sticky. Um... Am I the only one who thinks this issue is being made WAY MORE COMPLICATED than it needs to be? Seriously, GitTech seems to have the right idea. Look, try this; it's just 12 lines, really easy, and even has its own error-catcher. Function MirrorImage(ImageToMirror,FlipDirection) Local MirroredImage = CopyImage(ImageToMirror) If FlipDirection = 1;horizontal, left-to-right flip ScaleImage MirroredImage,-1,1 ElseIf FlipDirection = 2;vertical, top-to-bottom flip ScaleImage MirroredImage,1,-1 Else RuntimeError "The flip type has to be 1 or 2. You entered " + FlipDirection + ", doofus. XD" EndIf Return MirroredImage End Function ;Code example - MirrorImage() in action Global Image1 = LoadImage("image.bmp") Global Image2 = MirrorImage(Image1,1) Global Image3 = MirrorImage(Image1,2) There, that should do ya. Anyway, whatever you end up using, good luck! |
| ||
True, i was just trying to keep his animation frames the same. If you flip an animation strip whole image, then the animation order of things will also be flipped. My suggestion was to flip each section of the animated image, so as to preserve the order of the animation frames, making it easier to code :o) Regarding the image in his sig, why post it in every post... :o) |
| ||
LOL, I didn't think about what version I'm using! No wonder it won't work for you, I'm using version 1.64. I should probably update it. Thanks Adam for the code, I'll replace the scaleimage command with this. And thanks everyone else for being so incredibly helpful. And no, the WALNUT is not my signature image. I just put it there for this topic since this sort of has to do with Puki, and hes the one who gave me that nickname. This is the sig I normally use, although sometimes I do feel compelled to mix it up a bit. ![]() And the P.U.K.I game engine is so close to completion! All I have to do is add one more sample level, and two more sample chars. And fix the scaling thing. And after I release the first version of P.U.K.I, I will post a demo of my upcoming game, THE GAMES OF THE PAST COLLECTION! Hope You Enjoy, The Mighty WERDNA(Lord Of Darkness) ![]() What could this mysterious image be? a board game? drawn using pencil? with horribly uneven squares? The plot thickens.... |
| ||
Sweet a HardCore RPG game. |
| ||
LOL |