Hi, everybody.
I'm absolutely new to andEngine, but I have experience in Android development. So, please help me to solve this little problem.
I have a big picture - 1024x768, so I have to scroll it. Also I must put some clickable areas on this picture and place animated objects.
I've already done scrolling picture, but problem is that if I start scrolling from a clickable area I got a "click" result, but not scrolling. I don't know how to differ click from scroll.
Here is my class:
Using java Syntax Highlighting
public class AndEngineLayoutActivity extends LayoutGameActivity implements IOnSceneTouchListener {
private static final int CAMERA_WIDTH = 1000;
private static final int CAMERA_HEIGHT = 1000;
private Camera mCamera;
private Texture mTexture;
private TextureRegion mHouseMapTextureRegion;
private TextureRegion mWardrobeRoomRegion;
private static boolean isMove = false;
Parsed in 0.036 seconds, using
GeSHi 1.0.8.4
My onLoadScene:
Using java Syntax Highlighting
public Scene onLoadScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
final Sprite face = new Sprite(0, 0, this.mHouseMapTextureRegion);
final Sprite roomWardrobe = new Sprite(100,100,this.mRoomRegion){
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY){
if (AndEngineLayoutActivity.isMove){
return true;
}
Intent intent = new Intent(AndEngineLayoutActivity.this,Activity_Room.class);
startActivity(intent);
finish();
overridePendingTransition(0, 0);
return true;
}
};
scene.attachChild(face);
scene.attachChild(roomWardrobe);
scene.registerTouchArea(roomWardrobe);
scene.setOnSceneTouchListenerBindingEnabled(true);
//scene.setTouchAreaBindingEnabled(true);
scene.setOnSceneTouchListener(this);
return scene;
}
Parsed in 0.039 seconds, using
GeSHi 1.0.8.4
And my onSceneTouchEvent. I use flag isMove to prevent event onAreaTouched if I during scrolling touch this area. This func is so long cause I don't want to scroll my image out of borders.
Using java Syntax Highlighting
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pTouchEvent) {
if(pTouchEvent.getAction() == MotionEvent.ACTION_DOWN)
{
mTouchX = pTouchEvent.getMotionEvent().getX();
mTouchY = pTouchEvent.getMotionEvent().getY();
}
else if(pTouchEvent.getAction() == MotionEvent.ACTION_MOVE)
{
AndEngineLayoutActivity.isMove = true;
float currentX = pTouchEvent.getMotionEvent().getX();
float currentY = pTouchEvent.getMotionEvent().getY();
mTouchOffsetX = (mTouchX - currentX);
mTouchOffsetY = (mTouchY - currentY);
int maxX = (int)((bitmap.getWidth() / 2) - (mCamera.getWidth()/2));
int maxY = (int)((bitmap.getHeight() /2 ) - (mCamera.getHeight() /2));
final float maxLeft = 0;
final float maxRight = maxX;
final float maxTop = maxY;
final float maxBottom = 0;
// scrolling to left side of image (pic moving to the right)
if (currentX > mTouchX)
{
if (totalX == maxLeft)
mTouchOffsetX = 0;
if (totalX > maxLeft)
totalX = totalX + mTouchOffsetX;
if (totalX < maxLeft){
mTouchOffsetX = maxLeft - (totalX - mTouchOffsetX);
totalX = maxLeft;
}
}
// scrolling to right side of image (pic moving to the left)
if (currentX < mTouchX)
{
if (totalX == maxRight)
mTouchOffsetX = 0;
if (totalX < maxRight)
totalX = totalX + mTouchOffsetX;
if (totalX > maxRight){
mTouchOffsetX = maxRight - (totalX - mTouchOffsetX);
totalX = maxRight;
}
}
// scrolling to top of image (pic moving to the bottom)
if (currentY > mTouchY)
{
if (totalY == maxTop)
mTouchOffsetY = 0;
if (totalY > maxTop)
totalY = totalY + mTouchOffsetY;
if (totalY < maxTop){
mTouchOffsetY = maxTop - (totalY - mTouchOffsetY);
totalY = maxTop;
}
}
// scrolling to bottom of image (pic moving to the top)
if (currentY < mTouchY)
{
if (totalY == maxBottom)
mTouchOffsetY = 0;
if (totalY < maxBottom)
totalY = totalY + mTouchOffsetY;
if (totalY > maxBottom){
mTouchOffsetY = maxBottom - (totalY - mTouchOffsetY);
totalY = maxBottom;
}
}
float newScrollX = this.mCamera.getCenterX() - mTouchOffsetX;
float newScrollY = this.mCamera.getCenterY() - mTouchOffsetY;
this.mCamera.setCenter(newScrollX, newScrollY);
mTouchX = currentX;
mTouchY = currentY;
}
if(pTouchEvent.getAction() == MotionEvent.ACTION_UP){
AndEngineLayoutActivity.isMove = false;
}
return true;
}
Parsed in 0.049 seconds, using
GeSHi 1.0.8.4
If anybody knows how to help me solve my problem or to optimize this code, please help me. I read about ScrollDetector and TouchDetector, but I don't understand how to use it.