How can i do a mirror of a animation (like a mario game that goes right and left with the same moves and animation)? It's possible to use just one image with all frames and make a mirror just when needed?
Tks!
MB
Tks!
MB
player=mirror_image(player,5)
Function mirror_image(image_name,frames#) mirrorimage=CreateImage(ImageWidth(image_name),ImageHeight(image_name),frames*2) For loop=0 To frames-1 CopyRect 0,0,ImageWidth(image_name),ImageHeight(image_name),0,0,ImageBuffer(image_name,loop),ImageBuffer(mirrorimage,loop) Next LockBuffer ImageBuffer(image_name) LockBuffer ImageBuffer(mirrorimage) For floop=frames To (frames*2)-1 For loop=0 To ImageWidth(image_name)-2 For loop1=0 To ImageHeight(image_name)-2 CopyPixel ImageWidth(image_name)-1-loop,loop1,ImageBuffer(image_name,floop-frames),loop,loop1,ImageBuffer(mirrorimage,floop) Next Next Next UnlockBuffer ImageBuffer(mirrorimage) UnlockBuffer ImageBuffer(image_name) Return mirrorimage End Function
Graphics 640,480,32,2 ;setting these here so that I can modify this later to work with commandline or drag n drop Global ImageName$ = "elfmoves.bmp" Global FrameWidth% = 32 Global FrameHeight% = 32 Global FirstFrame% = 0 Global tempImage = LoadImage(ImageName) Global FrameCount% = ImageWidth(tempImage)/FrameWidth Global OutImageName$ = "new_" + Left(ImageName$, Len(ImageName$)-Len(ExtractFileExt(ImageName$))-1)+".bmp" Global XOffset = FrameCount * FrameWidth FreeImage tempImage tempImage = 0 ;images Global inImage = LoadAnimImage(ImageName, FrameWidth , FrameHeight, FirstFrame, FrameCount) Global NewImage = CreateImage((FrameWidth * FrameCount)*2, FrameHeight, FrameCount * 2) tempImage = CreateImage(FrameWidth, FrameHeight) ;first, copy the original frames to the new image SetBuffer ImageBuffer(NewImage) For Count = 0 To FrameCount -1 DrawImage inImage, Count * FrameWidth, 0, Count Next ;next copy and flip the frames and place them in the new image in the same sequence StartTime = MilliSecs() For Count = 0 To FrameCount -1 SetBuffer ImageBuffer(tempImage) Cls DrawImage inImage, 0, 0, Count tempImage = FlipImageH(tempImage) SetBuffer ImageBuffer(NewImage) DrawImage tempImage, XOffset + (Count * FrameWidth), 0 Next EndTime = MilliSecs() - StartTime ;SAVE THE IMAGE SaveImage(NewImage, OutImageName$) ;DISPLAY THE END RESULTS SetBuffer BackBuffer() DrawImage NewImage, 0,0 Text 0, ImageHeight(NewImage), "Done - file saved as: " + OutImageName$ Text 0, ImageHeight(NewImage) + 24, "Time taken to convert:" + EndTime + "ms" ;END OF PROGRAM WaitKey() FreeImage NewImage FreeImage inImage FreeImage tempImage EndGraphics End ;FUNCTION FlipImageH ;Accepts an image, flips it horizontally (using CopyRect), then returns the resulting image Function FlipImageH(srcImage) ;LOCAL VARS Local Width = ImageWidth(srcImage) Local Height = ImageHeight(srcImage) Local imgTemp = CreateImage(Width, Height) ;MAIN For X = 0 To ImageWidth(srcImage)-1 CopyRect X, 0, 1, Height, (Width-1) - X, 0, ImageBuffer(srcImage), ImageBuffer(imgTemp) Next Return imgTemp End Function ;FUNCTION ExtractFileName ;Accepts a filepath and returns the filename Function ExtractFileName$(sFilePath$) ;LOCAL VARS Local iStartPos% = 0 Local iSearchPos% = 0 Local iFilePathLength = 0 Local sFileName$ = "" ;BEGIN FUNCTION CODE iFilePathLength = Len(sFilePath$) iSearchPos% = iFilePathLength While (iStartPos% < 1) And (iSearchPos% > 1) iStartPos% = Instr(sFilePath$, "", iSearchPos%) iSearchPos% = iSearchPos% - 1 Wend If iStartPos = 0 Then ;if the filepath contains no backslashes sFileName$ = sFilePath$ Else sFileName$ = Right$(sFilePath$, iFilePathLength% - iStartPos%) EndIf Return sFileName$ End Function ;FUNCTION ExtractFileExt ;Accepts a filepath and returns the extension for the file Function ExtractFileExt$(sFilePath$) ;LOCAL VARS Local iStartPos% = 0 Local iSearchPos% = 0 Local iFilePathLength = 0 Local sFileExt$ = "" ;BEGIN FUNCTION CODE iFilePathLength = Len(sFilePath$) iSearchPos% = iFilePathLength While (iStartPos% < 1) And (iSearchPos% > 1) iStartPos% = Instr(sFilePath$, ".", iSearchPos%) iSearchPos% = iSearchPos% - 1 Wend If iStartPos = 0 Then ;if the filepath contains no . sFileExt$ = sFilePath$ Else sFileExt$ = Right$(sFilePath$, iFilePathLength% - iStartPos%) EndIf Return sFileExt$ End Function ;FUNCTION ExtractFilePath ;Accepts a filepath with filename and returns only the path ;i.e. pass c:\temp\test.txt the return value will be c:\temp\ Function ExtractFilePath$(sFilePath$) ;LOCAL VARS Local iStartPos% = 0 Local iSearchPos% = 0 Local iFilePathLength = 0 Local sFileExt$ = "" ;BEGIN FUNCTION CODE iFilePathLength = Len(sFilePath$) iSearchPos% = iFilePathLength While (iStartPos% < 1) And (iSearchPos% > 1) iStartPos% = Instr(sFilePath$, "", iSearchPos%) iSearchPos% = iSearchPos% - 1 Wend If iStartPos = 0 Then ;if the filepath contains no backslashes sFileExt$ = sFilePath$ Else sFileExt$ = Left$(sFilePath$, iStartPos%) EndIf Return sFileExt$ End Function
DrawImage image,200,200,frame
Const sw=640,sh=480 Graphics sw,sh,0,2 SetBuffer BackBuffer() img=LoadImage("arrow.bmp") DrawImage img,50,50 TFormImage img,-1,0,0,1 ; flip the image horizontally DrawImage img,250,50 WaitKey EndIt also works on 2D animations.