Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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;

        InitTouchPad();

        //create a stage and add touchpad
        stage = new Stage(800, 480,true, batch);
        stage.addActor(touchpad);
        Gdx.input.setInputProcessor(stage);

        //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);
        //setbound(x,y,width,height)
        touchpad.setBounds(0, 480 - 150, 150, 150);

    }

@Override
    public void render() {
        // TODO Auto-generated method stub
        Gdx.gl.glClearColor(0, 0, 0.2f, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        camera.update();

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

        batch.begin();
        blockSprite.draw(batch);
        batch.end();

        stage.act(Gdx.graphics.getDeltaTime());
        stage.draw();

    }

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

 
discard

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

Browse other questions tagged or ask your own question.