shaderProgram in cocos2d 3.0 doesn't work - cocos2d-iphone

I have just started with Cocos2d 3.0 after using 1.1 for a long time.
I wanted to test the shaders out and looked up some tutorials.
All tutorials seems to use the CCSprite property "shaderProgram".
When I try it like this:
renderTexture.sprite.shaderProgram = [[CCGLProgram alloc] initWithVertexShaderByteArray:ccPositionTextureA8Color_vert fragmentShaderByteArray:ccPositionTextureColorAlphaTest_frag]
Xcode gives me an error saying: "Property 'shaderProgram' not found on object type CCSprite *"
Is this property removed or changed from version 2.0 to 3.0 and how would I go about using it in Cocos2d 3.0?
Thanks!

Adding this import:
#import "CCNode_Private.h"
allows you to access CCNode's shaderProgram memberc

Related

How to change the image of a CCSprite in cocos2d v3.x

In cocos2d 2.x we change the image of a CCSprite using CCTexture. But in cocos2d 3.x CCTextureCache seems to be deprecated as Xcode warns me : "undeclared identifier 'CCTextureCache'". Or may be am I miss something as I'm new to cocos.
So how can we change the image of a CCSprite in v3 ??
Thank you.
I think I know how to do.
We have to use a spriteSheet built with TexturePacker [note : may be it's wrong to speak about external resources like it on SO] for example (let's say we have 2 images : monster_01.png and monster_02.png).
We add the .plist and the .png into xCode
We put the spritesheet in cache
and then we can create a CCSprite with a frame using a item of the spritesheet.
This image can be changed.
Some code :
3) We put in cache
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"monsterSpriteSheet.plist"];
4) We create the sprite
CCSprite * mySprite = [CCSprite initWithSpriteFrame: [CCSpriteFrame frameWithImageNamed: #"monster_01.png"]];
5) To change image :
[mySprite setSpriteFrame:[CCSpriteFrame frameWithImageNamed: #"monster_02.png"]];
This works perfectly with cocos2d v3.
I spent 6 hours to have this process. Sometimes I feel stupid.
You can do it by using this
CCSpriteFrameCache and after that you can change you sprite by using function setSpriteFrame of ccsprite.

Somethings wrong with GoogleMap SDK iOS

My app is using both UIkit and cocos2d. After using view with GoogleMap SDK and show cocos scene. xcode show this:
cocos2d: surface size: 0x0
Failed to make complete framebuffer object 0x8CDD
And the screen is black, and can do nothing except restart app.
I have searched so many website, so many people have same problem but no solution for that.
So is it impossible to use Google Map sdk with cocos2d? If not what can I do?
(Before using GoogleMapsdk I used MKMapview, it doesn't cause this problem but it's not as good as GoogleMap)
Google Maps uses OpenGL ES to render the map. Two OpenGL renderers can not be mixed, they both use their own GL context. Specifically on iOS there seems to be little support to run two GL views side by side (let alone on top of each other).
So no, for all intents and purposes mixing cocos2d and google maps on iOS is not possible.

Porting Cocos2d 1.0 to Cocos2d 2.0

I got one old game and I tied to update Cocos2d 2.0 SDK. I got some compilation error.
b2Vec2 gravity;
gravity.Set(0.0f, -10.0f);
self.world = new b2World(gravity, true);
Error: No matching constructor for initialization of 'b2World'
When I change this to below code then works but Box2D debug shapes are not drawn.
self.world = new b2World(gravity);
How to initialize Box2d world in right way that show debug shapes?
Replace the GLESDebugDraw files with those found in a newly created cocos2d 2.0 + Box2D project. Your version is still using GL ES 1.1 commands which don't work in cocos2d 2.x
Finally I got debug shape by replacing this draw function and GLESDebugDraw files.
-(void) draw
{
[super draw];
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
kmGLPushMatrix();
self.world->DrawDebugData();
kmGLPopMatrix();
}

after Cocos2d 2.0 migration, sprite placement is all wrong

I've just updated my project to Cocos2d v2.0 and after getting rid of all build errors, i can get it to run but the game seems to draw things in the wrong place. Buttons/menus are clickable where they're supposed to be, but the sprites show up in the wrong place, or not at all. (This project was my copying old files into a new v2.0 project from a template.)
I'm also getting openGL errors like this
OpenGL error 0x0502 in -[CCGLView swapBuffers] 280
OpenGL error 0x0502 in -[CCSprite draw] 532
OpenGL error 0x0502 in -[CCSprite draw] 532
OpenGL error 0x0502 in -[CCSprite draw] 532
OpenGL error 0x0502 in -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 556
So, I reread the migration post... removed the RootViewController stuff, etc, then created a new project from the v2.0 template and made my appDelegate look just like it. I double checked my CCSprite -draw method, looks just like it's supposed to in v2.0
No change. Still OpenGL errors and most of my sprites are out of place. (background seem fine, oddly enough.)
This is happening when using the 5.1 or 6.0b4 IOS Simulator
I'm at a loss.. :(
Anyone have any ideas? I've exhausted my search options and am just frustrated .. thanks ahead of time!
(FYI, this was a fully working v1.0.1 game)
UPDATE:
SUCCESS!!! So, I had a third part class (SWScrollView .h and CCNode+Autolayout.h) that was using
glPushMatrix() and glPopMatrix()
updating those to
kmGLPushMatrix() and kmGLPopMatrix() fixed all of the errors and sprite placement!!!
Cocos2D 2.0 uses OpenGLES2.0 but cocos2D 1.0 uses OpenGLES1.0.
Here is one similar thread, follow my answer. Replace ur draw function.

iOS 4.3 causes black screen (4.0-4.2 was fine) - MPMoviePlayerController at fault?

I've made a game that uses cocos2d to display graphics, and uses a lot of MPMoviePlayerController to display cutscenes.
The problem is - the game stopped working on iOS 4.3. It was fine up until iOS 4.2, but on iOS 4.3 the movies play OK, the gameplay also happens, but the screen is all black when not playing the movies.
I have a hard time tracking the problem. Suggestions?
Edit: I narrowed the thing down to MPMoviePlayerController - if I disable it, everything is fine. I guess something changed in 4.3?
MPMoviePlayerController's view is clear in 4.0-4.2, and black in 4.3 by default, what helped was:
MPMoviePlayerController* moviePlayer = ...
moviePlayer.view.backgroundColor = [UIColor clearColor];
MPMoviePlayerController* moviePlayer = ...
[moviePlayer.backgroundView setBackgroundColor:[UIColor whiteColor]];
// or set need color
read more in "MPMoviePlayerController Class Reference"