Android Question Display Sprite randomly

herryj

Member
Licensed User
Hi,
This may sound to lame for some experts, you guys. though forgive mi for I am still on the process of learning sprites.

I have here an image attached below, I slice this images in another class, and now I want to display this sliced images randomly,

can you give me any hint on how to do this or by giving a small code.

I've done displaying random image though the image has its separate file name unlike to this one.

Thanks for the advance help.

stage1.png
 

walterf25

Expert
Licensed User
Hi,
This may sound to lame for some experts, you guys. though forgive mi for I am still on the process of learning sprites.

I have here an image attached below, I slice this images in another class, and now I want to display this sliced images randomly,

can you give me any hint on how to do this or by giving a small code.

I've done displaying random image though the image has its separate file name unlike to this one.

Thanks for the advance help.

View attachment 31889
How do you slice the images?

you could probably add the images to an array or a list and assign a number to each image.

I would need to see more information on how you're doing this.
 

herryj

Member
Licensed User
Hi Walter,
Yes I added the image to an array.
Here it is

B4X:
' graphics Class module
Sub Class_Globals
    Public eshp1(6) As Sprite
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    Dim est1 As Sprite
    est1.Bitmap=LoadBitmap(File.DirAssets,"easy/stage1.png")
    eshp1(0).Bitmap=est1.Bitmap : eshp1(0).Region(256,6,202,206) : eshp1(0).MidAnchor
    eshp1(1).Bitmap=est1.Bitmap : eshp1(1).Region(6,394,117,102) : eshp1(1).MidAnchor
    eshp1(2).Bitmap=est1.Bitmap : eshp1(2).Region(6,226,202,102) : eshp1(2).MidAnchor
    eshp1(3).Bitmap=est1.Bitmap : eshp1(3).Region(137,394,100,102) : eshp1(3).MidAnchor
    eshp1(4).Bitmap=est1.Bitmap : eshp1(4).Region(6,6,236,206) : eshp1(4).MidAnchor
    eshp1(5).Bitmap=est1.Bitmap : eshp1(5).Region(222,226,168,154) : eshp1(5).MidAnchor
End Sub

I found some example here, though the image to be display randomly is only 1.


B4X:
SpriteList.Initialize
        android.Bitmap=LoadBitmap(File.DirAssets,"android.png")
        android.MidAnchor
        For i=0 To 9
            Dim newAndroid As Sprite
            newAndroid.Copy(android)
            newAndroid.Position(Rnd(68,gsv.VirtualWidth-64),Rnd(60,gsv.VirtualHeight-64))
            SpriteList.Add(newAndroid)
        Next
 
Top