如题如何让Cocos2dGameContainer和游戏内的canvas画面保持一致?就是1.10.2以前版本的效果。超出边界部分不显示。
提问虽然不一样,但想要的效果是一样的。
最简单方法就是把camera画面投到RenderTexture内, 然后用sprite显示该RenderTexture, 然后加个Material与shader在游戏初始化时传入左&右边界的世界坐标到material, 然后shader如下, 就是判断超出左右边范围时不渲染
CProgram vs %{
precision highp float;
#include <cc-global>
#include <cc-local>
in vec3 a_position;
in vec4 a_color;
out vec4 v_color;
out vec3 v_position;
#if USE_TEXTURE
in vec2 a_uv0;
out vec2 v_uv0;
#endif
void main() {
vec4 pos = vec4(a_position, 1);
#if CC_USE_MODEL
pos = cc_matViewProj * cc_matWorld * pos;
#else
pos = cc_matViewProj * pos;
#endif
#if USE_TEXTURE
v_uv0 = a_uv0;
#endif
v_color = a_color;
v_position = a_position;
gl_Position = pos;
}
}%
CCProgram fs %{
precision highp float;
#include <alpha-test>
#include <texture>
in vec4 v_color;
in vec3 v_position;
#if USE_TEXTURE
in vec2 v_uv0;
uniform sampler2D texture;
#endif
uniform vec2arg {
vec2 width_range;
};
void main() {
vec4 o = vec4(1, 1, 1, 1);
#if USE_TEXTURE
CCTexture(texture, v_uv0, o);
#endif
o *= v_color;
if (v_position.x < width_range.x || v_position.x > width_range.y) {
discard;
}
ALPHA_TEST(o);
#if USE_BGRA
gl_FragColor = o.bgra;
#else
gl_FragColor = o.rgba;
#endif
}
}%