Multi Floor Scrolling

Started by Hotshot, May 01, 2020, 23:10:24

Previous topic - Next topic

Hotshot

I have try do Multi Floor Scrolling and It only show 2 Floor on Screen where I want to make 10 of them.

I think there is two way of doing it, One is using createimage of 10 floor images into memory then show it on the screen in loop by user either want move left or right

or

I could used For Next of trying to display 10 floor images but I think I have calculate it wrong hence why it only show 2 floor images on the screen!

I am not sure which is better...


If InitSprite() = 0 Or InitKeyboard() = 0 Or OpenScreen(640,480,32,"App Title") = 0
   MessageRequester("Error!", "Unable to Initialize Environment", #PB_MessageRequester_Ok)
   End
EndIf

UsePNGImageDecoder()

Floor  = LoadSprite(1 ,"Land.png")

TransparentSpriteColor(1 ,RGB(255,0,255))  ; Floor

Repeat
      ClearScreen(0)
 
      ExamineKeyboard()
 
      ; show our sprite               
     
      ; Draw ground - Little Trick how to make Multi Background Scrolling!
      For x = 1 To 10  ;draw 10 ground sprites next to each other across bottom of screen            
          DisplayTransparentSprite(1,x*J+_Move ,350)
          J=J+165
          If j>=1650 : J=0 : EndIf
      Next
                       
      If KeyboardPushed(#PB_Key_Left) : _Move=_Move-1 : EndIf
     
      If KeyboardPushed(#PB_Key_Right): _Move=_Move+1 : EndIf
       
      ; put up a little message to the user that we're done
      If StartDrawing(ScreenOutput())
         DrawText(0,460,"Press any key to exit")
      Else
          MessageRequester("Error!", "Unable to Draw to ScreenOutput()", #PB_MessageRequester_Ok)
          End
      EndIf

      StopDrawing()

      FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End

chalky

You are adding 165 to J each iteration of your for-next loop, then multiplying it by x as well, so the x-coord is getting much larger than the screen width...

Moving J outside of your loop draws more than 2 sprites - though a loop of 10 still extends way beyond the visible area:

If InitSprite() = 0 Or InitKeyboard() = 0 Or OpenScreen(640,480,32,"App Title") = 0
   MessageRequester("Error!", "Unable to Initialize Environment", #PB_MessageRequester_Ok)
   End
EndIf

UsePNGImageDecoder()

Floor  = LoadSprite(1 ,"Land.png")

TransparentSpriteColor(1 ,RGB(255,0,255))  ; Floor

J=165

Repeat
      ClearScreen(0)

      ExamineKeyboard()

      ; show our sprite               
     
      ; Draw ground - Little Trick how to make Multi Background Scrolling!
      For x = 0 To 9  ;draw 10 ground sprites next to each other across bottom of screen            
          DisplayTransparentSprite(1,x*J+_Move ,350)
      Next
                       
      If KeyboardPushed(#PB_Key_Left) : _Move=_Move-1 : EndIf
     
      If KeyboardPushed(#PB_Key_Right): _Move=_Move+1 : EndIf
       
      ; put up a little message to the user that we're done
      If StartDrawing(ScreenOutput())
         DrawText(0,460,"Press any key to exit")
      Else
          MessageRequester("Error!", "Unable to Draw to ScreenOutput()", #PB_MessageRequester_Ok)
          End
      EndIf

      StopDrawing()

      FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End


BTW - I only changed the loop to start at 0 so the drawing started further to the left.

Hotshot

Thanks chalky and work great :)