【发布时间】:2012-01-09 03:51:55
【问题描述】:
我在 Andengine 中使用此方法通过设置相机的偏移量来滚动项目列表。
@Override
public void onScroll(ScrollDetector pScollDetector, int pPointerID,
float pDistanceX, float pDistanceY) {
//Disable the menu arrows left and right (15px padding)
if(mCamera.getXMin()<=15)
menuleft.setVisible(false);
else
menuleft.setVisible(true);
if(mCamera.getXMin()>mMaxX-15)
menuright.setVisible(false);
else
menuright.setVisible(true);
//Return if ends are reached
if ( ((mCurrentX - pDistanceX) < mMinX) ){
return;
}else if((mCurrentX - pDistanceX) > mMaxX){
return;
}
//Center camera to the current point
this.mCamera.offsetCenter(-pDistanceX,0 );
mCurrentX -= pDistanceX;
//Set the scrollbar with the camera
float tempX =mCamera.getCenterX()-CAMERA_WIDTH/2;
// add the % part to the position
tempX+= (tempX/(mMaxX+CAMERA_WIDTH))*CAMERA_WIDTH;
//set the position
//scrollBar.setPosition(tempX, scrollBar.getY());
//set the arrows for left and right
menuright.setPosition(mCamera.getCenterX()+CAMERA_WIDTH/2-menuright.getWidth(),menuright.getY());
menuleft.setPosition(mCamera.getCenterX()-CAMERA_WIDTH/2,menuleft.getY());
//Because Camera can have negativ X values, so set to 0
if(this.mCamera.getXMin()<0){
this.mCamera.offsetCenter(0,0);
mCurrentX=0;
}
}
问题是我将此作为我在活动中的第二个场景, 因此,当我导航回第一个活动时,由于相机被移动,第一个场景不在位置。
回到第一个场景时我可以重置相机吗?
我试过 Camer.reset() 无济于事。
有什么建议吗?
【问题讨论】: