Page 1 of 1
issues with sprites
Posted: Sat Mar 23, 2019 1:47 am
by dan yalte
Hi I am having issues using sprints. My program opens a window at 640X480 then i put up a background image of a blackjack table. my problem is i have not figured out how to draw the sprint on top of the blackjack table. I have a basic understanding of sprints but need more information. Do i use OpenWindowedScreen() on top of my already opened window. Is there an example where i can just change my background image and my sprite being used thanks
Re: issues with sprites
Posted: Sat Mar 23, 2019 2:24 am
by salutcava
hey dan, here is your example (made with the help of the PB help file), beware there is no error check in this code.
change de var called background.s
Use the left and right arrows to move the sprite.
Code: Select all
InitSprite():InitKeyboard()
OpenWindow(0,100,100,800,600,"SPlayer",#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0),0,0,800,600,#True,0,0,#PB_Screen_WaitSynchronization)
background.s = "c:\path\to\image.bmp" ; <=== CHANGE THE PATH HERE
;===loads the background image===
LoadSprite(0,background)
;===creates a sprite===
CreateSprite(1,100,100,#PB_Sprite_AlphaBlending) ; create or load a sprite, here we create a sprite
StartDrawing(SpriteOutput(1))
Box(0,0,100,100,0)
Circle(50,50,50,RGB(255,0,0))
StopDrawing()
TransparentSpriteColor(1,0)
Repeat
;===manages window events===
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_Gadget
If EventGadget() = 0
End
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
;===manages keyboard events===
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
x.i = x-1
EndIf
If KeyboardPushed(#PB_Key_Right)
x=x+1
EndIf
EndIf
;===The display is managed here : clears the screen, draws the background, then draws the sprite, and flips buffers
ClearScreen(RGB(0, 0, 0))
DisplaySprite(0,0,0)
DisplayTransparentSprite(1, 400+x, 300)
FlipBuffers()
Delay(1)
ForEver
Have Fun !
Re: issues with sprites
Posted: Thu Mar 28, 2019 9:24 am
by dan yalte
Hi there thanks for the example not sure why the sprite you draw in the example does not show up I think it's a colour issue but all good I just load my background image and load my card sprite in the foreground and all is good the only other small thing I changed was I changed DisplayTransparentSprite(1, 400+x, 300) to DisplaySprite(1, 400+x, 300) and all is good. it was still cool to have the DisplayTransparentSprite part there as it showed me what that will do in the above example it made all the black parts of the card clear as you could see the table underneath. All good information . The cool part now is I can work out a formula for card position on the table so I can deal out cards like I would on a real blackjack table. The reason I can reduce it to a formula is the screen size is fixed and each spot on the table has markers. So all I need is one variable for each seat position As i deal cards i look at the last position for any given seat and deal the next card so they overlap and carry on very cool. Can also do shuffles. or even flash cards. very cool. it looks so good wow...