Closed agGitHub closed 12 years ago
Try to instanciate your CCRenderTexture on the "render" (overrided) method.
I am new with Coco2D Android. Can you detail a little bit more what you mean ? Few lines àf code would be useful. Thanks !!
public class MyNode extends CCNode { @Override public void onEnter() { super.onEnter(); CCRenderTexture rt = CCRenderTexture.renderTexture(textureSize, textureSize); //.... } }
Is it more comprehensible ? +
Thanks for your answer. Still not working :( (but I am really new with Coco2D Android !!)
Now I have got the following error:
12-14 15:43:47.883: E/AndroidRuntime(5013): java.lang.NullPointerException
12-14 15:43:47.883: E/AndroidRuntime(5013): at org.cocos2d.nodes.CCAtlasNode.calculateMaxItems(CCAtlasNode.java:86)
12-14 15:43:47.883: E/AndroidRuntime(5013): at org.cocos2d.nodes.CCAtlasNode.
Here is my (very simple) code:
public class GameLayer extends CCColorLayer { private CCSprite _background;
public static CCScene scene()
{
CCScene scene = CCScene.node();
ccColor4B colorB4 = ccColor4B.ccc4(255, 255, 255, 255);
CCColorLayer layer = new GameLayer(colorB4);
scene.addChild(layer);
return scene;
}
public void onEnter() { super.onEnter(); doBackground(); }
protected GameLayer(ccColor4B color) { super(color);
this.setIsTouchEnabled(true);
}
private void doBackground() {
ccColor4B myColor = ccColor4B.ccc4(255,255, 255,255);
ccColor4F bgColor = ccColor4F.ccc4FFromccc4B(myColor);
_background = spriteWithColor(bgColor, 512);
CGSize winSize = CCDirector.sharedDirector().winSize();
_background.setPosition(winSize.width/2, winSize.height/2);
addChild(_background,-1);
}
private CCSprite spriteWithColor(ccColor4F bgColor, int textureSize) {
CCRenderTexture rt = CCRenderTexture.renderTexture(textureSize, textureSize);
rt.clear(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
rt.end();
return CCSprite.sprite((rt.getSprite()).getTexture());
}
}
Thanks a lot for your help and sorry for my stupid questions... (my 2nd day with Coco 2D...)
Without CCRenderTexture, does your code work ? Do you use the jar file or sources ? If sources, did you set "fps_images.png" in your asset folder ?
Thanks it works !!!!! You are a genius !! I can't believe it, so many hours lost just because of this stupid file...
I use the sources from ZhouWeikuan (not a jar). Is it the best choice ?
Thanks again for everything !
I just want to create a CRenderTexture with this simple code:
CCRenderTexture rt = CCRenderTexture.renderTexture(width, width);//width and height have the same values
But it returns a null pointer exception.
The issue occurs in the CCRenderTexture class when the object is initialized:
protected CCRenderTexture(int width, int height) { GL11ExtensionPack egl = (GL11ExtensionPack)CCDirector.gl; egl.glGetIntegerv(GL11ExtensionPack.GL_FRAMEBUFFER_BINDINGOES, oldFBO, 0); ///ETC.... }
Indeed, "CCDirector.gl" is equal to null which induces that "egl" is equal to null => crash on egl.glGetIntegerv(...).
Somebody knows how to fix this bug ? (which seems due to the Android Coco 2D framework)
Thanks !!!