Android Question Simple GameView question.

ZPaul2Fresh8

Member
Licensed User
Longtime User
First off, I am a beginner so go easy :)

Now I'm going through the tutorials of the GameView library since it seems easier for a beginner when dealing with Bitmaps and such associated with game creation. Now my question deals with loading a BACKGROUND into the GameView and making it scroll.

I get it to the background to show by declaring the variable in Process_Globals as so:

B4X:
Dim space as Bitmap

and then in the Activity_Create:

B4X:
space.Initialize(File.DirAssets, "space.png")
gv.SetBackgroundImage(space)

Now my problem is that if I declare the variable as a bitmap instead of a BitmapData then I don't have the member SrcRect which is required to move the image and if I declare it as a BitmapData and use the following code:

B4X:
space.Bitmap = LoadBitmap(File.DirAssets, "space.png")
gv.SetBackgroundImage(space)

I get an error that says the SetBackgroundImage was expecting a Bitmap but found BitmapData...

OR

If I use these lines I get a crash when launching

B4X:
space.Bitmap.Initialize(File.DirAssets, "space.png")
'space.Bitmap = LoadBitmap(File.DirAssets, "space.png") <---Doesn't work either
gv.SetBackgroundImage(space)


Any ideas? Is there a limit to what can be initialized at once? Like I said I am really green to using GameView...
 

stevel05

Expert
Licensed User
Longtime User
Setting the background image in that way will result in a static background. You should look at the related subs (CreateBackground and Timer1_Tick) in the gameviewsmiley example
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
I am trying to get my head around scrolling myself.

I think you need to DIM space as BitmapData

I am still trying to understand the SrcRect
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
OK I have a better understanding of the SrcRect now.

I have attached a project that (I hope) shows exactly what it is about.

I create a tall image that is composed of six separate images with the bottom image being a copy of the top image. The SrcRect selects a sub-image from the while image to be displayed where the DestRect points to. So we are basically looking at a viewport of the whole image. Most of the image is masked and out of view - we can only see the sub-set that the SrcRect points to.

Hopefully this helps.

It is a step closer to my slot machine!
 

Attachments

  • skrollin.zip
    261.6 KB · Views: 325
Upvote 0
Top