how to flip a sprite in smallbasic? We can rotate but flip I couldn't find

Fabricio Lima 5 Reputation points
2023-02-24T00:01:43.7833333+00:00

Hello,

Is there some way to flip a sprite in smallbasic? The program allows us to rotate but I couldn't find a way to flip sprite either an image.

Thanks.

Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
277 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Scout 136 Reputation points
    2023-02-28T22:36:59.1733333+00:00

    football-64x64

    It is better to create the flip images as an image list before using them.

    Otherwise a 64x64 bit flip takes 3 seconds.

    sprite = ImageList.LoadImage(Program.Directory + "\football-64x64.png")
    xsize = ImageList.GetWidthOfImage(sprite)
    ysize = ImageList.GetHeightOfImage(sprite)
    mirror = LDImage.Copy(sprite)
    For loop = 1 To 3
      Program.Delay(500)
      GraphicsWindow.DrawImage(sprite, 100, 100)
     LDImage.OpenWorkingImage(mirror)
     For y = 1 To ysize - 1
      For x = 1 To xsize - 1
        pixel = LDImage.GetPixel(sprite, x , y)
        LDImage.SetWorkingImagePixel(mirror, xsize - x , y , pixel)
      EndFor
     EndFor 
     LDImage.CloseWorkingImage(mirror) 
     GraphicsWindow.DrawImage(mirror, 100, 100)
    EndFor
    
    For loop = 1 to 20
      GraphicsWindow.DrawImage(sprite, 100, 100)
      Program.Delay(150)
      GraphicsWindow.DrawImage(mirror, 100, 100) 
      Program.Delay(150)
    EndFor
    
    1 person found this answer helpful.

  2. Kristian Virtanen 126 Reputation points
    2023-02-28T14:45:05.4433333+00:00

    Hi.

    Afaik, there is no inbuilt function for this. Maybe LitDev had something, but not sure anymore.

    But you can create such a function yourself. This code is untested due i dont have SB installed on my current laptop. You should thought be able to figure the idea and fix if i messed up something.

    [code]

    GraphicsWindow.Show()
    
    ' original
    sprite = ImageList.LoadImage("sprite.png")
    
    ' flipped copy
    mirror = ImageList.CreateImage(sprite.GetWidth(), sprite.GetHeight())
    
    For y = 0 To sprite.GetHeight() - 1
      For x = 0 To sprite.GetWidth() - 1
        mirror.SetPixel(sprite.GetWidth() - 1 - x, y, sprite.GetPixel(x, y))
      EndFor
    EndFor
    
    GraphicsWindow.DrawImage(sprite, 100, 100)
    GraphicsWindow.DrawImage(mirror, 200, 100)
    
    
    0 comments No comments