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 have set up a DigitalOnScreenControl in my game but the knob does not move. The base and the knob are drawn on the screen but the latter doesn't move as per the AndEngine example here.

Here is a snippet of my code:

this.mDigitalOnScreenControl = new DigitalOnScreenControl(300, 300, ResourceManager.getCamera(), ResourceManager.joystickControlBase,
                ResourceManager.joystickControlKnob, 0.1f, ResourceManager.getActivity().getVertexBufferObjectManager(),
                new IOnScreenControlListener() {

            @Override
            public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX,
                    final float pValueY) {
                    Log.v(TAG, "onControlChange");
            }
        });

        final Sprite controlBase = this.mDigitalOnScreenControl.getControlBase();
        final Sprite knob = this.mDigitalOnScreenControl.getControlKnob();
        controlBase.setAlpha(0.5f);
        controlBase.setOffsetCenter(0, 0);
        controlBase.setScaleCenter(10, 10);
                    controlBase.setScale(1.25f);
        knob.setScale(1.25f);
        this.mDigitalOnScreenControl.refreshControlKnobPosition();
        ResourceManager.getEngine().getScene().attachChild(this.mDigitalOnScreenControl);

The mDigitalOnScreenControl is a DigitalOnScreenControl object defined previously. I use a ResourceManager class to obtain texture regions and other game resources such as the camera amongst others. Note: Since the base and the knob are drawn, the ITextureRegions returned by the ResourceManager are valid. When I execute the program, there are no errors in DDMS.

The knob just doesn't move. Does anybody have an idea?

Thank you!

share|improve this question
    
Do you ever call refreshControlKnobPosition() in your update code? Is the knob logging onControlChange? –  Byte56 Feb 25 '13 at 19:12
    
1) If I put a Log.v(TAG, "msg") inside the onControlChange(), I get the verbose log at every screen update. This means that onControlChange() is being called. 2) To which update code are you referring? Thank you for your support. –  shailenTJ Feb 25 '13 at 20:06
    
Your main loop, or update loop. I'm not sure if you're required to update the knob position or it's done automatically. –  Byte56 Feb 25 '13 at 20:10
    
I proofread my code. The whole code snippet posted (and therefore the refreshControlKnobPosition() function) is run in the main loop (onLoadScene()). This bug is very strange. –  shailenTJ Feb 25 '13 at 20:22
1  
@shailenTJ It's actually pretty sensible as a child scene. The on screen controls relies on having its own relative coordinate system, so it knows how far you're pushing the knob from a fixed point, regardless of the outside scene coordinates. I think you should consider posting an answer to your question and accepting it. –  Cameron Fredman Feb 26 '13 at 22:29
show 5 more comments

1 Answer

up vote 1 down vote accepted

The DigitalOnScreenControl cannot be attached as a child to a scene. It must be attached as a childscene to the Engine's current Scene.

ResourceManager.getInstance().engine.getScene().setChildScene(joystickControl);

In the above code, joystickControl extends a DigitalOnScreenControl object. After that, depending on how your game is organised, you may need to sort the scenes, in case the DigitalOnScreenControl does not appear.

ResourceManager.getInstance().engine.getScene().sortChildren();

Also, read Cameron Fredman's comment why it is sensible to add the DigitalOnScreenControl object as a childscene.

share|improve this answer
    
Almost done. Now click the check mark next to your answer! :) –  Cameron Fredman Feb 28 '13 at 9:26
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.