Mirroring Sprite horizontal without api

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Mirroring Sprite horizontal without api

Post by Rings »

well, i have it done myself and will share the code.
And also i have learned using DrawingBuffer & DvrawingBufferPitch.
looks like an easy water-mirroring :)
Image

Code: Select all

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
  End
EndIf
If InitSprite3D() = 0
  MessageRequester("Error", "Direct3D system can't be initialized correctly", 0)
  End
EndIf

Procedure SpriteMirrorHorizontal(SpriteID)
;Mirrors a sprite horizontal
StartDrawing(SpriteOutput(SpriteID))
 IW = SpriteWidth(SpriteID) 
 IH = SpriteHeight(SpriteID)
 Buffer      = DrawingBuffer()             ; Get the start address of the screen buffer
 Pitch       = DrawingBufferPitch()        ; Get the length (in byte) took by one horizontal line
  
 *pxData1.LONG = Buffer
 *pxData2.LONG = *pxData1 + (IH-1)*Pitch

 mem=AllocateMemory(Pitch)
 For lines=0 To IH/2-1
  CopyMemory(*pxData1,mem,pitch)
  CopyMemory(*pxData2,*pxData1,pitch)
  CopyMemory(mem,*pxData2,pitch)
  *pxData1 + pitch
  *pxData2 - pitch
 Next
 StopDrawing() 
 If mem: FreeMemory(mem):EndIf
  
EndProcedure
If OpenScreen(800,600, 32, "Sprite")

  LoadSprite(0, "Data\Geebee2.bmp", #PB_Sprite_Texture)
  TransparentSpriteColor(0, RGB(255, 0, 255)) ; Our pink is transparent :)
    StartDrawing(SpriteOutput(0))
     Box(0,0,30,30,RGB(250,250,50))
    StopDrawing()
  CopySprite(0,1,  #PB_Sprite_Texture)
  SpriteMirrorHorizontal(1)
  TransparentSpriteColor(1, RGB(255, 0, 255)) ; Our pink is transparent :)
  CreateSprite3D(0, 0)
  CreateSprite3D(1, 1)
  ZoomSprite3D(1,SpriteWidth(1),SpriteHeight(1)*1.5)
  f1.f=1;0.5
  Repeat
    FlipBuffers()
   
    ClearScreen(RGB(200,200,255))
    StartDrawing(ScreenOutput())
     Box (0,130+SpriteHeight(0),800,600-130-SpriteHeight(0),RGB(50,50,250))
    StopDrawing()
    ; Draw our sprite
    If Start3D()
      DisplaySprite3D(0, 200, 130);original
      b=b+f1
      If b>5
       f1=f1*-1
      EndIf 
      If b<-5
       f1=f1*-1
      EndIf 

      ZoomSprite3D(1,SpriteWidth(1),SpriteHeight(1)*1.5 - b)
      DisplaySprite3D(1, 200, 130+SpriteHeight(0),64)
      Stop3D()
    EndIf
    ExamineKeyboard()
    x+1
  Until x > 2500 Or KeyboardPushed(#PB_Key_Escape)
Else
  MessageRequester("Error", "Can't open a screen !", 0)
EndIf
End  
Mirroring a Sprite should go as a native SpriteCommand.....
SPAMINATOR NR.1
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

Looks like an good old Amiga Copper-List effect :) nice indeed. thx for sharing.
Tranquil
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Hi Rings, perhaps you have interest on this:
http://www.purebasic.fr/english/viewtopic.php?t=24226
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

ups, i searched whole day for a fast flipping routine,
found nothing and write my own.
And now i see your post in that thread, which works like the
same as mine routines http://www.purebasic.fr/english/viewtop ... highlight=

cruel world......
SPAMINATOR NR.1
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

:wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply