Home > Basic4Android, Games development > Android Flappy Bird clone code is on the way!

Android Flappy Bird clone code is on the way!

I’m having major headaches with scaling the graphics to work on different screen sizes.

 

Here’s proof though that I’m working on it. It’s attached.
image

 

Advertisements
  1. February 24, 2014 at 4:12 pm

    Looks great Andy!

  2. Andy McAdam
    February 24, 2014 at 4:34 pm

    thanks! I manage to get it looking right on one device, then as soon as I change to another the graphics go crazy and draw different sizes and in the wrong positions. I’m using accelerated surfaces which gives me the scaled option for the surface and I’m using the density variable from the reflection library to get the screen density but just getting totally confused! I’ll keep triyng. If I’m still stuck in a few days I’ll just post what I’ve done so far and leave it open to someone else to fix it.

  3. Asmoro
    February 24, 2014 at 10:53 pm

    Nice try, can’t wait to test it out on my Android devices.

    Is it because you’re using B4a 3.2 that you have problems with the sizes/scales or is it
    something else?

    Asmoro

  4. February 25, 2014 at 8:10 am

    Not sure if it is of any help but this is the formula I use when I scale graphics in B4A:

    iTemplatewidth=800
    iTemplateHeight=1280
    Dim delta As Double
    delta = (100%x + 100%y) / ((iTemplatewidth + iTemplateHeight) * 100dip / 100) – 1
    ScaleRate = 1 + 1 * delta

    I then develop everything for 800×1280 and use the ScaleRate to adjust per device.

    My bitmap scale function then looks something like this (Using ABExtDrawing):

    Public Sub MakeBitmapScaleHeight(iPicture As Bitmap, iHeight As Int) As Bitmap
    Dim xBuildPicture As Bitmap
    Dim xBuildCanvas As Canvas

    Dim innerScale As Float
    innerScale = iHeight/iPicture.Height

    Dim iWidth As Int
    iWidth = iPicture.Height * innerScale

    xBuildPicture.InitializeMutable(iWidth,iHeight)
    xBuildCanvas.Initialize2(xBuildPicture)

    Dim paint As ABPaint
    paint.Initialize
    paint.setDither(True)
    paint.setAntiAlias(True)
    paint.setFilterBitmap(True)

    Dim matrix As ABMatrix
    matrix.postScale(innerScale, innerScale)
    exDraw.drawBitmap4(xBuildCanvas, iPicture, matrix, paint)

    Recycle(iPicture)
    Return xBuildPicture
    End Sub

  5. Andy McAdam
    February 25, 2014 at 8:38 am

    Thanks AlwaysBusy (need a better name for you). I have found that the presence of hardware acceleration makes a difference. I wasn’t using gpu support on the emulator as it seems to freeze after a few seconds, but I think that’s graphics driver related on my laptop. But I found the scale changes completely just based on whether GPU support is enabled or not. What I’ll do is only develop for hardware accelerated devices as this should cover most people, my Galaxy S2 phone has it and that’s 3 years old! Expect a new code download available in the next few days.

  6. February 25, 2014 at 12:31 pm

    Just call me Alain 🙂 Interesting facts about the different behaviours when GPU is enabled or not. Wouldn’t have thought this could make such a difference (besides speed).

  7. September 8, 2014 at 7:49 pm

    Always your code for resize bitmap are awesome! But i have one problem! The “bitmap scaled” is not created to center of canvas but on left! There are any solution for this??

    • Andy McAdam
      September 15, 2014 at 8:13 am

      I’m not sure the answer to this I’m afraid. I’ve moved onto using the libgdx library for games, which is awesome and much easier to use. I would recommend reading any posts I have made about libgdx as it’s much more advanced than using accelerated surfaces.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: