0

I am developing a game. In this I need background image scrolling vertically from top to bottom.

Actually my emulator size is 320*720(width*height) but my background image size is 320*3840. So now I need background image scroll from Height: 720 to 3840.

I have code for a background image scrolling but background image not scrolling properly. Please help me.
Here is my code,

        private Bitmap mBackgroundImageFar; //my image
        private int mBGFarMoveY = 0;

                 mBGFarMoveY = mBGFarMoveY + 2;

        int newFarY = mBackgroundImageFar.Height - (- mBGFarMoveY);

        if (newFarY <= 0) 
        {
            mBGFarMoveY =0;
            canvas.DrawBitmap (mBackgroundImageFar,0,mBGFarMoveY,null);
        } 
        else
        {
            canvas.DrawBitmap (mBackgroundImageFar,0,mBGFarMoveY,null);
            canvas.DrawBitmap (mBackgroundImageFar,0,newFarY, null);
        }

If I write any mistakes please excuse me.

Thanks & Regard's, Chakri.

Chakri
  • 123
  • 1
  • 1
  • 10

2 Answers2

1

Are you using any game engine? if no, easy way to solve your problem is using game engine. For example solving in andengine is CameraScene or ParallaxBackground

Andrew F
  • 1,712
  • 2
  • 15
  • 24
  • I am not using any game engine. Regards,chakri – Chakri Jul 17 '12 at 09:50
  • try this http://stackoverflow.com/questions/4775650/android-moving-background-image-while-navigating-through-views – Andrew F Jul 17 '12 at 09:57
  • Thank you, but I am developing a game in Mono droid tool. How can I use a game engine in my application. – Chakri Jul 17 '12 at 12:21
  • sorry, but it's the first time I heard about the Mono droid tool. I'm using eclipse and just need to add the engine library to the project to work with it. – Andrew F Jul 17 '12 at 13:18
1
    private Bitmap mBackgroundImageFar; //my image
    private int mBGFarMoveY = 0;

             mBGFarMoveY = mBGFarMoveY + 2;

    int newFarY = mBackgroundImageFar.Height - (+ mBGFarMoveY);

    if (newFarY <= 0) 
    {
        mBGFarMoveY =0;
        canvas.DrawBitmap (mBackgroundImageFar,0,mBGFarMoveY,null);
    } 
    else
    {
        canvas.DrawBitmap (mBackgroundImageFar,0,mBGFarMoveY,null);
        canvas.DrawBitmap (mBackgroundImageFar,newFarY,0, null);
    }
Chakri
  • 123
  • 1
  • 1
  • 10
  • Some explanation would be nice. – Andrew Barber Oct 17 '12 at 12:04
  • Changed the -mBGFarMoveY direction to +mBGFarMoveY then it moves vertically and here canvas.DrawBitmap (mBackgroundImageFar,0,newFarY, null); changed to canvas.DrawBitmap (mBackgroundImageFar,newFarY,0, null); then mBGFarMoveY moves on the Y-axis. – Chakri Oct 17 '12 at 12:08