开发者

AndEngine and Android: OnAreaTouched in a for loop not remaining unique

I'm using andengine for android for the first time. I'm creating a simple list of text that simply needs 开发者_StackOverflow社区to be able to call the same method but send a different variable accroding to its position on the list. The list does not need to scroll and is short. I decided to use simple text and created a for loop to make them for me from a string array.

The loop works and creates the text properly but when touching they all perform the last touch assignment instead of the corresponding one.

Does the onAreaTouched code need to be referred to or is it saved some where once the touch area is registered.

here it is:

  for(x =1; x<base.locale.length;x++){
                 textLoc[x-1]=new Text(10,(110+(x*30)),base.getmFont(),
                                        base.locale[x],HorizontalAlign.CENTER){
                    @Override
                    public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {

                        base.moveListen(Integer.toString(x));
                loadNewScene();
                        return true;
                    }

                };

              scene.getLastChild().attachChild(textLoc[x]);
              scene.registerTouchArea(textLoc[x]);

            }


Does that code compile? As in this line:

base.moveListen(Integer.toString(x));

you are refering to the non-final loop-variable x.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜