October 28, 2020, 11:04:09 PM

Author Topic: Multi Floor Scrolling  (Read 461 times)

Offline Hotshot

  • Jr. Member
  • **
  • Posts: 30
Multi Floor Scrolling
« on: May 01, 2020, 11:10:24 PM »
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...

Code: [Select]
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

Offline chalky

  • Jr. Member
  • **
  • Posts: 63
Re: Multi Floor Scrolling
« Reply #1 on: May 02, 2020, 02:41:14 PM »
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:

Code: [Select]
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.

Offline Hotshot

  • Jr. Member
  • **
  • Posts: 30
Re: Multi Floor Scrolling
« Reply #2 on: May 02, 2020, 11:16:01 PM »
Thanks chalky and work great :)

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal