Gamewindow background not showing

enonod

Well-Known Member
Licensed User
Longtime User
I am having a little trouble putting a background image on a gamewindow.
I have added the gw object and no errors occur but neither does an image.
The image is in the same directory. It worked on an Image component.

B4X:
   Form1.Show
   gw.New1("Form1",0,0,321,321)
   gw.DrawBackgroundImage(AppPath & "\grid 20x20.png")

I am having trouble adjusting from Delphi. I am unsure of the significance between adding an object from the IDE Tools Add Object menu, adding the DLL of the same name via the Tools Component menu etc.

Some help here please.
 

derez

Expert
Licensed User
Longtime User
I tried to use png in my game program and it works, however I had another case in which png format created problems,
Try to convert the image to jpg and see if it makes a difference.
 

enonod

Well-Known Member
Licensed User
Longtime User
Thanks for the suggestion derez. I have now tried jpg and bmp but the image does not show. I must have missed a step but cannot find what. I used the 'Sprite' example to derive this test and used the same steps but there may be something hidden that is not in the actual code.
 

agraham

Expert
Licensed User
Longtime User
This is the minimum needed to display a background.
B4X:
Sub App_Start
   Form1.Show
   gw.New1("Form1",0,0,240,320)
   gw.DrawBackgroundImage(AppPath & "\grid 20x20.png")
   doevents
   gw.tick
End Sub
You need "gw.tick" to force a redraw. Normally this would be in a timer. In this case as "gw.tick" is in App_Start the doevents is essential. I think this is because without it the Form doesn't actually get to draw itself until App_Start exits and then the normal Form drawing seems to take place after the game window drawing leaving a blank form. Having a doevents lets the Form do its' initial drawing and then "gw.tick" can do its' thing.
 

enonod

Well-Known Member
Licensed User
Longtime User
Thank you very much agraham.
I think most problems I have are to do with understanding the cycle or sequence of things in B4PPC and what is essential. Is there somewhere that I could have found that information had I followed the right path?

[Edit] My interpretation of this situation is that I didn't actually go far enough by trying to see each stage happen as I code it.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Is there somewhere that I could have found that information had I followed the right path?
Not directly. You need some knowledge of how Windows apps, which are event driven, are structured and the role of messages and the applications' message loop to understand how things interact to explain things like this.
 
Top