------

[ AD ] Port Monitor ( Try to use a Best WebSite Monitoring Tool )

------
public GameScene() {
    super(1, 1);

    setBackground(background = new FixedBackground(Textures.background));

    // Create the Bob sprite.
    bob = new Sprite(100, 220, Textures.bob.getWidth(), Textures.bob.getHeight());
    bob.setTexture(Textures.bob);

    // Add the Bob sprite to the first layer.
    add(0, bob);
}


@Override
public void onTouchDown(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
	// This is called when you press down on the screen.
}

@Override
public void onTouchMove(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
	// This is called when you move your finger over the screen. (ie pretty much every frame if your holding your finger down)

	// Here we'll just make Bob follow your finger.
	bob.x = x - (Textures.bob.getWidth() / 2);
	bob.y = y - (Textures.bob.getHeight() / 2);
}

@Override
public void onTouchUp(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
	// And this is called when you stop pressing.
}



The first and second parameters are the x and y positions of where you press (duh),
and the third is the actual event send by android if you happen to need that,
 then the last two are only used if you target android 2.1 or up,
'pointerCount' is the amount of fingers the user is currently holding down
and 'pointerId' is which of them this event is for.

And then in 'onTouchMove()' we just set Bob's position to be where you're pressing.
(to see that it actually works)
(The width/2 and height/2 are just to make it centered)

+ Recent posts