Andengine(gles2)-ButtonSprite不会在点击时做出反应 [英] Andengine (gles2) - ButtonSprite don't react on click

查看:68
本文介绍了Andengine(gles2)-ButtonSprite不会在点击时做出反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

mButton = new ButtonSprite(400  , 400, myTiledTextureRegion.getTextureRegion(0), myTiledTextureRegion.getTextureRegion(1), 
            activity.getVertexBufferObjectManager(), new OnClickListener() {

                @Override
                public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX,
                        float pTouchAreaLocalY) {

                                 Toast.makeText(MenuScene.this.activity, "Clicked", Toast.LENGTH_LONG).show();


                }
            });

    this.attachChild(mButton);

我的问题是,当我单击按钮时,我没有收到烤面包消息(记录相同),并且myTiledTextureRegion.getTextureRegion(1)的aslo sprite也没有更改.不知道为什么吗?

我可以单击按钮,但是没有反应.我尝试使用AnimatedSprite来测试资源,并且可以正确显示动画.为什么我的ButtonSprite OnClickListener和sprite更改不起作用?

I can click on button, but there is no reaction. I tried use AnimatedSprite to test resources and it display animation correctly. Why my ButtonSprite OnClickListener and sprite change there don' work ?

我加载资源的方式:

BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    mBitmapTextureAtlas = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 512, 256, TextureOptions.NEAREST);
    myTiledTextureRegion =  BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mBitmapTextureAtlas, activity, "btn.png", 1, 3);

    try {
        mBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 1));
        mBitmapTextureAtlas.load();
    } catch (TextureAtlasBuilderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

我在Scene类上做所有事情,因为我只有一个活动(和许多场景).感谢您的帮助.

I do everything on my Scene class, because i have only one activity (and many scenes). Thanks for help.

推荐答案

查看是否存在此问题...在将按钮附加到this.attachChild(mButton);之前,请确保同时将触摸区域注册到this.registerTouchArea(mButton);

see if this is the issue ... before you attach the button with this.attachChild(mButton); be sure and also register the touch area with this.registerTouchArea(mButton);

这篇关于Andengine(gles2)-ButtonSprite不会在点击时做出反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆