Chakri
Chakri

Reputation: 123

Background image scrolling vertically

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.

Upvotes: 0

Views: 1840

Answers (2)

Chakri
Chakri

Reputation: 123

    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);
    }

Upvotes: 1

Andrew F
Andrew F

Reputation: 1711

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

Upvotes: 1

Related Questions