Trouble with scrolling with canvas

Problems with Canvas, OpenGL, etc...

Trouble with scrolling with canvas

Postby jpb1614 » Wed Dec 07, 2011 5:24 pm

I'm very new to programming and am currently trying to make a simple game for android. The problem I'm having is the way the view is scrolling. By the logic here, I believe the sprite should stay in the center of the screen, but it doesn't. The view does follow the sprite, but not at the same speed if that makes sense. As in the view kind of lags behind. It's not jumpy so I know it's not running slowly. What surprises me though is I'm setting my scrolling rectangle equal to player x location - (display width/2), and then same for the y axis. I'm hoping you guys can help me out and figure out why the sprite isn't staying in the center of the view. Any help will be greatly appreciated. Thanks

-Jarryd

Code: Select all
private static Rect displayRect = null; //rect we display to
private Rect scrollRect = null; //rect we scroll over our bitmap with

Display display = getWindowManager().getDefaultDisplay();
displayWidth = display.getWidth();             
displayHeight = display.getHeight();   

displayRect = new Rect(0, 0, displayWidth, displayHeight);
scrollRect = new Rect(0, 0, displayWidth, displayHeight);
//Setting the new upper left corner of the scrolling rectangle

    newScrollRectX = ((int)player.getXLocation() - (displayWidth/2));
    newScrollRectY = ((int)player.getYLocation() - (displayHeight/2));
//This is in my onDraw method, so it updates right before the player is drawn

    scrollRect.set(newScrollRectX, newScrollRectY,
    newScrollRectX + displayWidth, newScrollRectY + displayHeight);
//bmLargeImage is a 1440X1440 background

    canvas.drawBitmap(bmLargeImage, scrollRect, displayRect, paint);

canvas.drawBitmap(player.getBitmap(),(float)player.getX(player.getSpeedX()), (float)player.getY(player.getSpeedY()), null);
jpb1614
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Dec 07, 2011 5:20 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 4 guests