Programación de juegos para iPhone: problema de líneas negras de tilemap

when i run my app on my iphone (not on simulator), strange black lines appears only when i start moving the map. So here is my code for moving the tilemap :

- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {

    if (recognizer.state == UIGestureRecognizerStateBegan) {    

        CGPoint touchLocation = [recognizer locationInView:recognizer.view];
        touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
        touchLocation = [self convertToNodeSpace:touchLocation];                

    } else if (recognizer.state == UIGestureRecognizerStateChanged) {    

        CGPoint translation = [recognizer translationInView:recognizer.view];
        translation = ccp(translation.x, -translation.y);
        CGPoint newPos = ccpAdd(self.position, translation);
        self.position = [self boundLayerPos:newPos];  
        [recognizer setTranslation:CGPointZero inView:recognizer.view];    

    } else if (recognizer.state == UIGestureRecognizerStateEnded) {

        float scrollDuration = 0.2;
        CGPoint velocity = [recognizer velocityInView:recognizer.view];
        CGPoint newPos = ccpAdd(self.position, ccpMult(ccp(velocity.x, velocity.y * -1), scrollDuration));
        newPos = [self boundLayerPos:newPos];

        [self stopAllActions];
        CCMoveTo *moveTo = [CCMoveTo actionWithDuration:scrollDuration position:newPos];            
        [self runAction:[CCEaseOut actionWithAction:moveTo rate:1]];            


preguntado el 28 de agosto de 11 a las 01:08

1 Respuestas

Accumulating deltas will produce artifacts due to floating-point rounding issues. You'll get better results by placing tiles at a fixed location in space, and moving everything with an affine transform. An in-between solution is to accumulate a single absolute offset and adding it to the starting position of each tile (you'll obviously have to cache each start position somewhere).

Respondido 28 ago 11, 06:08

well I'm kind of noob i don't understand how to do that - hugo411

@the1nz4ne: Then stick to the second approach I suggested. Simply remember where each tile started life and hold an offset accumulator that is initially zero. Each time a move event is registered, add the movement to the accumulator, and set each tile to its original position plus the accumulator. - Marcelo Cantos

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.