Android,如何在两个函数之间传递值?

时间:2014-05-23 12:58:51

标签: java android opencv andengine

我正在尝试将 PosX PosY 值传递给onLoadScene函数,但我无法通过各种方式找到解决方案。任何帮助将非常感谢。

public class GameField extends LayoutGameActivity implements CvCameraViewListener2
{
      @Override
      public Scene onLoadScene() {
                 this.mScene = new Scene();
                 spritePic1.setPosition((int)PosX- textRegPic1.getWidth()/2,(int) PosY- textRegPic1.getHeight()/2);

    return this.mScene;
        }
        @Override
        public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

                mRgba = inputFrame.rgba();  

                        PosX= Math.round(data2[i]);
                        PosY = Math.round(data2[i+1]);            
               return mRgba; 
        }
}

我编辑了我的问题。 OnLoadScene是LayoutGameActiviy的方法。这就是我无法向onLoadScene添加任何参数的原因。

1 个答案:

答案 0 :(得分:3)

  public Scene onLoadScene(float PosX,float PosY) {//PosX,PosY is float you can take as per your choice
             this.mScene = new Scene();
             spritePic1.setPosition((int)PosX- textRegPic1.getWidth()/2,(int) PosY- textRegPic1.getHeight()/2);

return this.mScene;
    }

用于调用功能

onLoadScene(PosX,PosY)
相关问题