嵌套的内部类ABar和BBar是否可以访问主类的变量?例如:
public class Foo {
public ABar abar = new ABar();
public BBar bbar = new BBar();
public int someCounter = 0;
public class ABar {
public int i = 0;
public void someMethod(){
i++;
someCounter++;
}
}
public class BBar {
public void anotherMethod(){
bbar.someMethod();
someCounter++;
}
}
}
// then called using: //
Foo myFoo = new Foo();
myFoo.bbar.anotherMethod();
Run Code Online (Sandbox Code Playgroud)
编辑
似乎我输入的代码如果我先试过它就会起作用; 我试图在没有太具体的情况下获得帮助.代码我实际上遇到了麻烦
由于错误'无法对非静态字段进行静态引用'而失败
public class Engine {
public Stage stage = new Stage();
// ...
public class Renderer …Run Code Online (Sandbox Code Playgroud) 我已经扩展了GLSurfaceView并实现了我自己的GLSurfaceView.Renderer来创建我的第一个相对简单的2D OpenGLES游戏.
我一直在使用以下代码测试我的游戏onCreate方法,它将表面视图设置为内容视图,从中我获得了一个恒定的60fps.
60fps活动:
mGLView = new OpenGLTest1SurfaceView(this);
setContentView(mGLView);
Run Code Online (Sandbox Code Playgroud)
但是现在我已经转移到了XML布局,所以我可以在屏幕的右下角放置一个admob叠加层,
admob xml:
<Frame Layout...
<...OpenGLTest1SurfaceView...
<com.google.ads.adView...
Run Code Online (Sandbox Code Playgroud)
admob活动:
setContentView(R.layout.main);
Run Code Online (Sandbox Code Playgroud)
现在我应用程序以看似随机的间隔在43fps和60fps之间波动.我查看了LogCat并且GC没有过度运行(每20秒左右一次).
任何帮助将不胜感激,因为我希望能够在不久的将来通过我的OpenGL应用程序货币化.