Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am adding a touchpad control to my game, using TexturePacker for loading images into the image-atlas. I have followed this tutorial to add the joystick. Everything is the same apart from the loading assets part. This is how I am adding the control:

//in create
ta = new TextureAtlas(Gdx.files.internal("image-atlases/pages-info.atlas"));

        camera = new OrthographicCamera();
        camera.setToOrtho(false, 800, 480);

        batch = new SpriteBatch();

        blockSpeed = 5;


        //create a stage and add touchpad
        stage = new Stage(800, 480,true, batch);

        //create block sprite
        blockTextureRegion = ta.findRegion("block");

        blockSprite = new Sprite(blockTextureRegion);
        //set position to the left bottom of screen
        blockSprite.setPosition(800-blockSprite.getWidth()/2, 480-blockSprite.getHeight()/2);

//end create

private void InitTouchPad(){
        //adding touchpad controls
        //create a touchpad skin
        touchpadSkin = new Skin();
        //set background image
        touchBackgroundRegion = ta.findRegion("touchBackground");
        touchpadSkin.add("touchBackground", touchBackgroundRegion.getTexture());
        //set knob image
        touchKnobRegion = ta.findRegion("touchKnob");
        touchpadSkin.add("touchKnob", touchKnobRegion.getTexture());
        touchpadStyle = new TouchpadStyle();
        //create drawable's from touchpad skin
        //touchBackground = touchpadSkin.getDrawable("touchKnob");
        //touchKnob = touchpadSkin.getDrawable("touchBackground");
        //apply the drawables to the touchpad style
        touchpadStyle.background = touchpadSkin.getDrawable("touchBackground");
        touchpadStyle.knob = touchpadSkin.getDrawable("touchKnob");
        //create new touchpad with the created style
        touchpad = new Touchpad(10, touchpadStyle);
        touchpad.setBounds(0, 480 - 150, 150, 150);


    public void render() {
        // TODO Auto-generated method stub, 0, 0.2f, 1);;


        //add touchpad controls
        blockSprite.setX(blockSprite.getX() + touchpad.getKnobPercentX()*blockSpeed);
        blockSprite.setY(blockSprite.getY() + touchpad.getKnobPercentY()*blockSpeed);




And for the output, all my assets are preloaded on the screen, the touchpad is nowhere looking like a joystick control. The images are jumbled over each other the movement of the sprite is in opposite direction..

share|improve this question
I believe you need to change something in your create method: blockSprite.setPosition(800-blockSprite.getWidth()/2, 480-blockSprite.getHeight()/2); don't these positions start at 0 for the bottom left? you placing them in the top-right corner, rather than 0,0 at the bottom-left? – wes Jun 21 '13 at 11:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.