我想扩展内置的libgdx类GLFrameBuffer,但不明白我应该为构造函数写什么。
GLFrameBuffer已经有另一个子类FrameBuffer,它使用下面的构造函数,最后一个是混淆的主题。
FrameBuffer () {}
protected FrameBuffer (GLFrameBufferBuilder<? extends GLFrameBuffer<Texture>> bufferBuilder) {
super(bufferBuilder);
}
public FrameBuffer (Pixmap.Format format, int width, int height, boolean hasDepth) {
this(format, width, height, hasDepth, false);
}
public FrameBuffer (Pixmap.Format format, int width, int height, boolean hasDepth, boolean hasStencil) {
FrameBufferBuilder frameBufferBuilder = new FrameBufferBuilder(width, height);
frameBufferBuilder.addBasicColorTextureAttachment(format);
if (hasDepth) frameBufferBuilder.addBasicDepthRenderBuffer();
if (hasStencil) frameBufferBuilder.addBasicStencilRenderBuffer();
this.bufferBuilder = frameBufferBuilder;
build();
}
请注意,没有对超类构造函数的调用,并且其超类没有(可见的(无参数构造函数。为什么允许这样做?这两个类都有没有代码的私有无参数构造函数。如果我完全复制 FrameBuffer 类并重命名它,我会收到一条消息,说我必须显式调用另一个构造函数。
编辑:libgdx 版本 1.9.8
你所谓的私有构造函数实际上并不是私有的。
它们是默认构造函数,它们的可见性级别default
而不是private
。这是在未指定访问修饰符时应用的访问修饰符(因此称为 default(
在 java 中,任何带有默认访问修饰符的内容都可以由同一包中的其他类访问。
这些类都在同一个包中,com.badlogic.gdx.graphics.glutils
.
FrameBuffer ()
构造函数实际上调用它不是构造函数super
参数。