마침내 이것을 수행하는 방법을 발견했습니다.
게임을 설정하는 방법은 각 항목이 자체적으로 그려지는 것입니다. 그들은 spritebatch가 주어지며 그것을 가지고 할 수 있습니다. 나는 여러 가지 이유에서 그렇게했다. 항목 목록을 포함하는 항목 관리자가 있습니다. 각 항목에는 다양한 속성이 있습니다. 각 항목에는 다른 독립 메소드와 함께 자체 렌더링 메소드가 있습니다. 여기에 마지막 일 것입니다 :
정상적인 항목의 알파 마스킹 사용하지 않는 방법 렌더링 : 그래서
public void render(SpriteBatch batch, int renderLayer) {
if(renderLayer == Integer.parseInt(render_layer)){ // be in the correct render layer
batch.draw(item.region,
item.position.x, // position.x
item.position.y, // position.y
0, //origin x
0, //origin y
item.region.getRegionWidth() , //w
item.region.getRegionHeight(), //h
item.t_scale, //scale x
item.t_scale, //scale y
item.manager.radiansToDegrees(item.rotation)); //angle
}
}
을가, 올바른 이미지, 위치, 규모 감있는의 SpriteBatch를 넘겨진다을하고 회전, 그리고 그 것입니다.
내가 여기 어떻게 놀아 후 : 검은 형태를 포함 alphaMask라는 TextureRegion이 있습니다
public void render(SpriteBatch batch, int renderLayer) {
if(renderLayer == Integer.parseInt(render_layer)){
batch.enableBlending();
//draw the alpha mask
drawAlphaMask(batch, item.position.x, item.position.y, item.region.getRegionWidth(), item.region.getRegionHeight());
//draw our foreground elements
drawForeground(batch, item.position.x, item.position.y, item.region.getRegionWidth(), item.region.getRegionHeight());
batch.disableBlending();
}
}
: https://gist.github.com/mattdesl/6076846을 잠시 동안,이 마지막으로 알파 마스크를 사용해야하는 항목에 대한했다. 그것은 모든 이미지,하지만의이 인스턴스에서의이 모양/이미지를 가정 해 봅시다 수 있습니다
private void drawAlphaMask(SpriteBatch batch, float x, float y, float width, float height) {
//disable RGB color, only enable ALPHA to the frame buffer
Gdx.gl.glColorMask(false, false, false, true);
// Get these values so I can be sure I set them back to how it was
dst = batch.getBlendDstFunc();
src = batch.getBlendSrcFunc();
//change the blending function for our alpha map
batch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ZERO);
//draw alpha mask sprite
batch.draw(alphaRegion,
x, // position.x
y, // position.y
0, // origin x
0, // origin y
alphaRegion.getRegionWidth(), // w
alphaRegion.getRegionHeight(), // h
item.t_scale, // scale x
item.t_scale, // scale y
item.manager.radiansToDegrees(item.rotation)); // angle
//flush the batch to the GPU
batch.flush();
}
는 다양한 있습니다
여기 ![A "beam"](https://i.stack.imgur.com/3sgr1.png)
그 이상이라는 기능입니다 해당 이미지를 사용 어떤 "모양"에도 적용 할 수있는 "재료" 어떤 경우이든 그 중 하나가 spriteRegion 변수에 할당됩니다.그래서 위라는 drawForeground 방법과 같이 해당 이미지 사용
![enter image description here](https://i.stack.imgur.com/vcU6J.png)
:
private void drawForeground(SpriteBatch batch, float clipX, float clipY, float clipWidth, float clipHeight) {
//now that the buffer has our alpha, we simply draw the sprite with the mask applied
Gdx.gl.glColorMask(true, true, true, true);
batch.setBlendFunction(GL10.GL_DST_ALPHA, GL10.GL_ONE_MINUS_DST_ALPHA);
batch.draw(spriteRegion,
clipX, // corrected center position.x
clipY, // corrected center position.y
0, //origin x
0, //origin y
spriteRegion.getRegionWidth() , //w
spriteRegion.getRegionHeight(), //h
item.t_scale, //scale x
item.t_scale, //scale y
item.manager.radiansToDegrees(item.rotation)); //angle
//remember to flush before changing GL states again
batch.flush();
// set it back to however it was before
batch.setBlendFunction(src, dst);
}
모두가 바로 바탕 화면 빌드에서 작동하는지, 그리고 "생성 할 수의 그것은 이것이다 지금 가정 해 봅시다 안드로이드와 GW에서 그러나
![enter image description here](https://i.stack.imgur.com/hqcfc.png)
: 멋지게 게임에서 벽돌 빔 "(또는 무엇이든) T는 빌드하기 때문에 (결국 libgdx를 사용하고 있습니다) 알파 마스크를 통합하지 않고 전체 벽돌 사각형을 렌더링했습니다. 주변을 둘러 보는이 많이 나는이 발견되면
는 : https://github.com/libgdx/libgdx/wiki/Integrating-libgdx-and-the-device-camera
그리고 안드로이드에서이 문제를 해결하기를 나는이 같은 MainActivity.java에서 onCreate 방법 수정 :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
cfg.r = 8;
cfg.g = 8;
cfg.b = 8;
cfg.a = 8;
initialize(new SuperContraption("android"), cfg);
if (graphics.getView() instanceof SurfaceView) {
SurfaceView glView = (SurfaceView) graphics.getView();
// force alpha channel - I'm not sure we need this as the GL surface
// is already using alpha channel
glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
}
}
을 그리고 그 안드로이드를 수정 .
libgdx에게 webGl에게 알파 채널을주의 깊게 알리기 위해 GWT에 알리는 방법을 알 수 없기 때문에 여전히 gwt에서 제대로 작동하는 방법을 알아낼 수 없습니다. 나는 더 쉽거나 덜 비싼 방법으로 이런 일을하는 방법에 관심이있다.
GWT에서이 작업을 수행하는 방법을 아는 분은 다른 답으로 게시하십시오. 여기
은 당신이 텍스처 문제를보고 싶다면 GWT가 구축되지 않은 작업 :
https://supercontraption.com/assets/play/index.html
당신이 알파 채널을 사용하여이를 달성 할 수 없음을? –
어떻게하면됩니까? – user2989675