Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use tile coordinates instead of the regular coordinates in cocos2d
    text
    copied!<p>I am still new to cocos2d and I have this problem that when I am using the ccp coordinates it stays at same position even when I move to the next screen. I came to the conclusion it must be that I am not using the tiles coordinates. So I need some help converting.</p> <pre><code> - (CGPoint)tileCoordForPosition:(CGPoint)position { float x = floor(position.x / map.tileSize.width); float levelHeightInPixels = map.mapSize.height * map.tileSize.height; float y = floor((levelHeightInPixels - position.y) / map.tileSize.height); return ccp(x, y); } -(CGRect)tileRectFromTileCoords:(CGPoint)tileCoords { float levelHeightInPixels = map.mapSize.height * map.tileSize.height; CGPoint origin = ccp(tileCoords.x * map.tileSize.width, levelHeightInPixels - ((tileCoords.y + 1) * map.tileSize.height)); return CGRectMake(origin.x, origin.y, map.tileSize.width, map.tileSize.height); } </code></pre> <p>that is what i use to translate regular coordinates into tile map coordinates.</p> <p>now I am trying to spawn an enemy at a certain position specifically (0,0)</p> <pre><code> -(void)addsaw{ CCSprite *saw = [CCSprite spriteWithFile:@"saw.png"]; // Determine where to spawn the target along the Y axis CGSize winSize = [[CCDirector sharedDirector] winSize]; int minY =saw.contentSize.height/2; int maxY = winSize.height - saw.contentSize.height/2; int rangeY = maxY - minY; int actualY = ( rangeY) + minY; //THIS IS THE PROBLEM RIGHT HERE saw.position = ccp(0,0); [self addChild:saw]; // Create the actions id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-saw.contentSize.width/2, actualY)]; id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished2:)]; [saw runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; saw.tag = 1; [_saws addObject:saw]; } </code></pre> <p>How do I change the ccp of my addsaw so I can have it spawn at the tile (0,0) rather than the cocos2d regular (0,0) </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload