如何在Android cocos2d中添加UISLIDER



嗨,

在这里做一个应用程序,我正在Android中使用cocos2d做小游戏。我需要显示 uislide,但我不知道如何显示。我试过了,但我没有任何想法,我正在做下面的应用程序代码,就像我动态拍摄表面视图一样,请任何人建议我如何显示滑块以及如何将图像视图、文本视图放入 xml 文件。

你好世界层:

public class HelloWorldLayer extends CCColorLayer {
    static HelloWorldLayer layer;
    CGSize winSize;
    CCSprite home,target;
    protected HelloWorldLayer(ccColor4B color) {
        super(color);
        // TODO Auto-generated constructor stub
        winSize = CCDirector.sharedDirector().displaySize();
        this.setIsTouchEnabled(true);
        home= CCSprite.sprite("banana.png");
        home.setPosition(winSize.width/2,winSize.height/2);
        this.addChild(home);
    }
    public static CCScene scene() {
        // TODO Auto-generated method stub
        //Creates scene  
        CCScene scene = CCScene.node();
        layer = new HelloWorldLayer(ccColor4B.ccc4(225, 225,225, 225));
        //adds layer to scene
        scene.addChild(layer);
        return scene;
    }
    @Override
    public boolean ccTouchesEnded(MotionEvent event) {
        CGPoint location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), event.getY()));
        if (CGRect.containsPoint(home.getBoundingBox(), location)) { 
            CCDirector.sharedDirector().replaceScene(CCFadeTransition.transition(0.5f,GamestartLayer.scene()));
            removeAllChildren(true);  
        }
        return true;
    }
}

您可以在 cocos2d 游戏活动中动态添加 UI 视图,如下所示

EditText txv=new EditText(context);
txv.setText("ABC");
CCDirector.sharedDirector().getActivity().addContentView(txv,layoutParams);

您可以使用相同的方法来使用Android的其他UIview。

最新更新