当我从视图控制器调用动画时,我试图在视图控制器上调用 cocos3d 动画,然后出现错误。
" cocos2d: Using Director Type:CCDirectorTimer [ ERROR ] cocos23Layer 需要一个控制器来渲染 3D 场景。2013-08-29 11:54:56.419 MaskedCal[3854:c07] * -[cocos23Layer initWithController:], /Users 中的断言失败/34in/桌面/cocos23/cocos23/cocos23/cocos3d/cocos3d/Scenes/CC3Layer.m:74"
这是我的视图控制器,我想在其中调用我的 cocos3d 动画
- (void)setupCocos2D { EAGLView *glView = [EAGLView viewWithFrame:self.view.bounds pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8 depthFormat:0 // GL_DEPTH_COMPONENT16_OES ]; [[CCDirector sharedDirector] setOpenGLView:glView]; // Create the customized CC3Layer that supports 3D rendering. CC3Layer* cc3Layer = [cocos23Layer node]; // cc3Layer = [cocos23Layer layerWithColor: ccc4(100, 120, 220, 255)]; //[cc3Layer scheduleUpdate]; // self.view = glView; // [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; cc3Layer.cc3Scene = [cocos23Scene scene]; CC3ControllableLayer* mainLayer = cc3Layer; // // CCScene *scene = [CCScene node]; // [scene addChild: mainLayer]; // [[CCDirector sharedDirector] runWithScene: scene]; mainLayer.contentSize = CGSizeMake(2048, 1320); [CCDirector sharedDirector].animationInterval = (1.0f / 60.0f); [CCDirector sharedDirector].displayStats = YES; [[CCDirector sharedDirector] enableRetinaDisplay: YES]; [[CCDirector sharedDirector] runWithScene:mainLayer]; }
*这是我的 cocos23scene 动画发生的地方 *
-(无效)初始化场景{
// Create the camera, place it back a bit, and add it to the scene
CC3Camera* cam = [CC3Camera nodeWithName: @"Camera"];
cam.location = cc3v( 0.0, 0.0, 6.0 );
[self addChild: cam];
// Create a light, place it back and to the left at a specific
// position (not just directional lighting), and add it to the scene
CC3Light* lamp = [CC3Light nodeWithName: @"Lamp"];
lamp.location = cc3v( -2.0, 0.0, 0.0 );
lamp.isDirectionalOnly = NO;
[cam addChild: lamp];
// This is the simplest way to load a POD resource file and add the
// nodes to the CC3Scene, if no customized resource subclass is needed.
[self addContentFromPODFile: @"hello-world.pod"];
// Create OpenGL buffers for the vertex arrays to keep things fast and efficient, and to
// save memory, release the vertex content in main memory because it is now redundant.
[self createGLBuffers];
[self releaseRedundantContent];
// Select an appropriate shader program for each mesh node in this scene now. If this step
// is omitted, a shader program will be selected for each mesh node the first time that mesh
// node is drawn. Doing it now adds some additional time up front, but avoids potential pauses
// as each shader program is loaded as needed the first time it is needed during drawing.
[self selectShaderPrograms];
// With complex scenes, the drawing of objects that are not within view of the camera will
// consume GPU resources unnecessarily, and potentially degrading app performance. We can
// avoid drawing objects that are not within view of the camera by assigning a bounding
// volume to each mesh node. Once assigned, the bounding volume is automatically checked
// to see if it intersects the camera's frustum before the mesh node is drawn. If the node's
// bounding volume intersects the camera frustum, the node will be drawn. If the bounding
// volume does not intersect the camera's frustum, the node will not be visible to the camera,
// and the node will not be drawn. Bounding volumes can also be used for collision detection
// between nodes. You can create bounding volumes automatically for most rigid (non-skinned)
// objects by using the createBoundingVolumes on a node. This will create bounding volumes
// for all decendant rigid mesh nodes of that node. Invoking the method on your scene will
// create bounding volumes for all rigid mesh nodes in the scene. Bounding volumes are not
// automatically created for skinned meshes that modify vertices using bones. Because the
// vertices can be moved arbitrarily by the bones, you must create and assign bounding
// volumes to skinned mesh nodes yourself, by determining the extent of the bounding
// volume you need, and creating a bounding volume that matches it. Finally, checking
// bounding volumes involves a small computation cost. For objects that you know will be
// in front of the camera at all times, you can skip creating a bounding volume for that
// node, letting it be drawn on each frame.
[self createBoundingVolumes];
// ------------------------------------------
// That's it! The scene is now constructed and is good to go.
// To help you find your scene content once it is loaded, the onOpen method below contains
// code to automatically move the camera so that it frames the scene. You can remove that
// code once you know where you want to place your camera.
// If you encounter problems displaying your models, you can uncomment one or more of the
// following lines to help you troubleshoot. You can also use these features on a single node,
// or a structure of nodes. See the CC3Node notes for more explanation of these properties.
// Also, the onOpen method below contains additional troubleshooting code you can comment
// out to move the camera so that it will display the entire scene automatically.
// Displays short descriptive text for each node (including class, node name & tag).
// The text is displayed centered on the pivot point (origin) of the node.
// self.shouldDrawAllDescriptors = YES;
// Displays bounding boxes around those nodes with local content (eg- meshes).
// self.shouldDrawAllLocalContentWireframeBoxes = YES;
// Displays bounding boxes around all nodes. The bounding box for each node
// will encompass its child nodes.
// self.shouldDrawAllWireframeBoxes = YES;
// If you encounter issues creating and adding nodes, or loading models from
// files, the following line is used to log the full structure of the scene.
LogInfo(@"The structure of this scene is: %@", [self structureDescription]);
// ------------------------------------------
// And to add some dynamism, we'll animate the 'hello, world' message
// using a couple of actions...
// Fetch the 'hello, world' object that was loaded from the POD file and start it rotating
CC3MeshNode* helloTxt = (CC3MeshNode*)[self getNodeNamed: @"Hello"];
CCActionInterval* partialRot = [CC3RotateBy actionWithDuration: 1.0
rotateBy: cc3v(0.0, 30.0, 0.0)];
[helloTxt runAction: [CCRepeatForever actionWithAction: partialRot]];
// To make things a bit more appealing, set up a repeating up/down cycle to
// change the color of the text from the original red to blue, and back again.
GLfloat tintTime = 8.0f;
ccColor3B startColor = helloTxt.color;
ccColor3B endColor = { 50, 0, 200 };
CCActionInterval* tintDown = [CCTintTo actionWithDuration: tintTime
red: endColor.r
green: endColor.g
blue: endColor.b];
CCActionInterval* tintUp = [CCTintTo actionWithDuration: tintTime
red: startColor.r
green: startColor.g
blue: startColor.b];
CCActionInterval* tintCycle = [CCSequence actionOne: tintDown two: tintUp];
[helloTxt runAction: [CCRepeatForever actionWithAction: tintCycle]];
}