I wanted to follow a tile map game tutorial for Cocos2D:
http://www.raywenderlich.com/29458/how-to-make-a-tile-based-game-with-cocos2d-2-x
However, it seems I can't follow this with Cocos2D 3.0 as the new Cocos2D doesn't seem to even include CCTMXLayer and CCTMXTiledMap.
I suppose I could install an older version of Cocos2D, but that could open a whole new can of worms. Is there some up to date tutorial or system for tile map games?
Thanks
Found a similar question with up to date version of Cocos2D objects:
"How To Make a Tile-Based Game with Cocos2D 2.X" Make this tutorial with cocos2d V3
for example:
HelloWorldScene.h
cpp
// Inside the HelloWorld class declaration
cocos2d::Sprite *_player;
HelloWorldScene.cpp
cpp
// Inside the init method, after setting "_background ="
TMXObjectGroup *objects = _tileMap->getObjectGroup("Objects");
CCASSERT(NULL != objects, "'Objects' object group not found");
auto spawnPoint = objects->getObject("SpawnPoint");
CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
int x = spawnPoint["x"].asInt();
int y = spawnPoint["y"].asInt();
_player = Sprite::create("Player.png");
_player->setPosition(x, y);
addChild(_player);
setViewPointCenter(_player->getPosition());
Related
ive run into some trouble with my spritebuilder project and i cant find a workaround. Im using the flappyfly tutorial to create a game.
In the tutorial there is an Obstacle.ccb in spritebuilder and obstacle.h/m in xcode. The obstacles get spawned into the main scene with this code
- (void)spawnNewObstacle {
CCNode *previousObstacle = [_obstacles lastObject];
CGFloat previousObstacleXPosition = previousObstacle.position.x;
if (!previousObstacle) {
// this is the first obstacle
previousObstacleXPosition = firstObstaclePosition;
}
Obstacle *obstacle = (Obstacle *)[CCBReader load:#"Obstacle"];
obstacle.position = ccp(previousObstacleXPosition + distanceBetweenObstacles, 0);
[obstacle setupRandomPosition];
obstacle.zOrder = DrawingOrderPipes;
[_physicsNode addChild:obstacle];
[_obstacles addObject:obstacle];
}
What i want to accomplish is to have these obstacles still spawning randomly. I dont want my hero to collide with the obstacles, instead i want the obstacles to act as a physics body, so you can jump on it, the problem is that when i disable hero and obstacle collision, the mainscene still imports the obstacles.m but no physics is being applied, even though physics is on in the obstacles.ccb, and the hero is able to go through the obstacles. The only way i can make it an actual physics body is to add the obstacles.ccb to the mainscene.ccb under the physics node. This works but then of course obstacles dont spawn randomly. Any workaround?
If you want them to keep spawning and for your hero to be able to jump on them without having to go to game over, i suggest setting a collision group for them
Is there something to replace CCLayerColor, CCLayerGradient etc inside Sprite Kit?
It was always easy to create simple filled rectangles in cocos2d, but I don't find any out of the box solutions in Sprite Kit so far.
As always, it should be platform independent so no iOS only code please (i.e., inside Sprite Kit).
Do you mean
SKSpriteNode *rect = [SKSpriteNode spriteNodeWithColor:[UIColor whiteColor] size:CGSizeMake(70, 70)];
I am new to cocos2d and i went through many tutorials on tiled map . And than , I have made one tmx map using tiled. In that i made one meta layer. Now, i stuck at one issue, i want to invisible my meta layer in my map .i used this code
[self.meta.visible = no];
meta layer is my first tile layer. i want to invisible this just for better view & i also trying for collision detection .i have also added my layer & set its property like following
CCTMXLayer * Layer;
#property (atomic,retain) CCTMXLayer * Layer;
[self addchild:self.meta];
Now, I don't know how to do this?
Try this code. Use Meta layer name according to your tileMap.
CCTMXLayer *meta = [tileMap layerNamed:#"Meta"];
meta.visible = NO;
See this image, names are case sensitive.
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();
}
Recently I migrate my project to Kobold2D 1.1 with Cocos2D 1.1beta2 inside for iPad Retina Display. But when I run my project and try to put a TMX tile map, the program hung up. The problem is CCTexture2D is call in InitWithImage and there's no Case for texture format AI88. Because of that, program goes to default and hang up.
I add to the code:
case kCCTexture2DPixelFormat_AI88:
data = malloc(POTHigh * POTWide);
info = kCGImageAlphaOnly;
context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, NULL, info);
break;
Is the same config as kCCTexture2DPixelFormat_A8 and now code works. I used a TMX made with Tile Editor 0.8 and uses a simple PNG not in any texture packer. The name inside TMX is fondomaze.png but in the project I must rename to fondomaze-ipad.png.
Hope you find useful. Now I can breathe relax with my project still working!
Discover a workaround for Retina Display iPad... Must to increase malloc by 4.
data = malloc(POTHigh * POTWide * 4);
Hope helps people who want to work with RD iPad.