# How to move sprite as if not rotated when rotated 90 degrees?

We're making a Tetris like game and need help rotating shapes.

Moving the shape works when there is no rotation.

However, after rotation, snapping the shape to the grid fails because the vector between the shape's current position and destination is affected by the amount of rotation (e.g., rotated 90 degrees).

As a simple example, let's assume a shape consists of one square and currently sits at (8, 0).

If the user rotates the shape 90 degrees (ignore that this functionally does nothing since the shape is only one square) then wants to move the shape to (1,0), what should the vector be? And how do you generalize the vector math?

We're using Swift 3 for an iOS game.

    if isShapePosValid(shape: curShape) {
let firstTile = curShape.getLowestTile()
let nearestBoardTile = getNearestBoardTile(shapeTile: firstTile)!
let newTilePos = firstTile.parent!.convert(nearestBoardTile.position, from: nearestBoardTile.parent!)
let moveVector = CGVector(point: newTilePos - firstTile.position)
let move = SKAction.move(by: moveVector, duration: 0.1)
curShape.run(move) {
self.printShapeToBoard(shape: curShape)
}
}

fileprivate func rotateShape(shape: BoardShapeSprite) {
let rotate = SKAction.rotate(byAngle: CGFloat(Double.pi/2), duration: 0.1)
shape.run(rotate)
}

fileprivate func printShapeToBoard(shape: ShapeSprite) {
let tiles = shape.getTiles().filter{ \$0.value != .Empty }

for t in tiles {
let boardTile = getNearestBoardTile(shapeTile: t)
boardTile?.setValue(value: .Taken)
}
}

• Can you show us the code which does the rotation? – Philipp Jul 31 '17 at 11:27
• @Philipp yup, just added – GameNoviceDev01 Jul 31 '17 at 17:04