Sprite bug?

Just starting out? Need help? Post your questions and find answers here.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 617
Joined: Tue Jan 04, 2011 6:21 pm

Sprite bug?

Post by SPH »

PB 6.12

Incomprehensible!

Look at this short code and tell me why the sprite I'm drawing isn't always the right one!

Code: Select all

InitSprite()
InitKeyboard()

OpenScreen(1920,1080,32,"Sprite")

LoadSprite(0,"d:/amy.bmp")

DisplaySprite(0,0,0)

taille_x=36
taille_y=42


nb=1
For u=0 To 8
  For i=1 To 8
    GrabSprite(nb,i*taille_x,u*taille_y,taille_x,taille_y)
    nb+1
  Next
Next

;;;

For i=1 To nb-1
    DisplaySprite(i,20+i*taille_x,400)
Next

FlipBuffers()
Repeat
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_All)

I'm not including the sprite table because the code is easy to read without it.

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
SPH
Enthusiast
Enthusiast
Posts: 617
Joined: Tue Jan 04, 2011 6:21 pm

Re: Sprite bug?

Post by SPH »

It only displays the sprites from the first row!

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 212
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: Sprite bug?

Post by moulder61 »

The For/Next loop before FlipBuffers() will run from 1 to 71 rather than 0 to 71.

nb in a previous nested loop will be 72. Could that be it?

Moulder.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
User avatar
SPH
Enthusiast
Enthusiast
Posts: 617
Joined: Tue Jan 04, 2011 6:21 pm

Re: Sprite bug?

Post by SPH »


!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
benubi
Enthusiast
Enthusiast
Posts: 236
Joined: Tue Mar 29, 2005 4:01 pm

Re: Sprite bug?

Post by benubi »

1. 1080 x 768 is not a standard resolution (I changed to 1024x768)

2. I modified one code so it scrolls the sprites, and also grabs the original table as sprite #0

It seems to be complete, starting with 'A' and finishing with '|'. I see nothing missing or grabbed at the wrong place.
(on PB 6.21 6.12 6.30, W10/64bit) It behaves the same on all PB versions I tested, but maybe I am missing something?

Code: Select all

InitSprite()
InitKeyboard()

OpenScreen(1024,768,32,"Sprite")
StartDrawing(ScreenOutput())
For u=0 To 5
  For i=0 To 10
    DrawText(i*20,u*20,Chr(65+x),RGB(Random(115),Random(115),Random(255)),RGB(Random(255),Random(255),Random(255)))
    x+1
  Next
Next
StopDrawing()

GrabSprite(0,0,0,220,120)
taille_x=20
taille_y=20

nb=1
For u=0 To 5
  For i=0 To 10
    GrabSprite(nb,i*taille_x,u*taille_y,taille_x,taille_y)
    nb+1
  Next
Next

;;;

x_offset=-1024
Repeat
  FlipBuffers()
  ClearScreen(0)
DisplaySprite(0,0,0)
For i=1 To nb-1
  DisplaySprite(i,(i*taille_x) - x_offset,400) ; erreur dans les numeros de sprites !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Next
x_offset+1
If x_offset>((nb+1)*taille_x)
  x_offset=-1024
EndIf 
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_All)
Olli
Addict
Addict
Posts: 1272
Joined: Wed May 27, 2020 12:26 pm

Re: Sprite bug?

Post by Olli »

Code: Select all

InitSprite()
InitKeyboard()
examindesktops()
w = desktopwidth(0)
h = desktopheight(0)
OpenScreen(w,h,32,"Sprite")

StartDrawing(ScreenOutput())
For u=0 To 5
  For i=0 To 10
    DrawText(i*20,u*20,Chr(65+x),RGB(Random(115),Random(115),Random(255)),RGB(Random(255),Random(255),Random(255)))
    x+1
  Next
Next
StopDrawing()

GrabSprite(0,0,0,220,120)
taille_x=20
taille_y=20

nb=1
For u=0 To 5
  For i=0 To 10
    GrabSprite(nb,i*taille_x,u*taille_y,taille_x,taille_y)
    nb+1
  Next
Next

;;;

x_offset=-1024
Repeat
  FlipBuffers()
  ClearScreen(0)
DisplaySprite(0,0,0)
For i=1 To nb-1
  DisplaySprite(i,(i*taille_x) + x_offset,400)
Next
x_offset+1
If x_offset>((nb+1)*taille_x)
  x_offset=-1024
EndIf 
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_All)
Post Reply