suhbataar
2004.01.15, 05:37 PM
I just started looking at Cocoa and ObjC, and I am - as many others, I'm sure - surprised at how easy it is to get going. I am working on a Tetris-clone in order to get myself going. In it, I have arranged it thus that each piece is represented ideally by a 4x4 "matrix". I then have an array of the 4 points of the lower-left corner of those squares in the matrix that are in the actual shape. The coordinates (in the surrounding coordinate system) of the lower left corner in the matrix are stored as another point, to represent the position of the shape.
To rotate the shapes I tried using combined NSAffineTransforms that first translated the origin to an axis-of-rotation-point, then rotated and then translated the other way. However, I didn't get it to work, and ended up defining the matrix for the transformation instead, using NSAffineTransform with that instead.
Everything worked fine until I started letting the shapes fall down. Now when I do that, and take in key events that rotate it too, the rotations start going in wide circles, and the shapes start jumping all over the place. I know this might not be expressed in the clearest possible way, but any ideas of what is going wrong would be helpful.
I'd also like to ask some advice on Timers while I'm at it. I'm using an NSTimer to step the game forward. What are the pros & cons of doing this as opposed to using a separate thread? Also I'm using keyCodes to determine what key has been pressed, not letting those events that are repeated (isARepeat) do anything, so that the player has to keep tapping keys instead of just holding one down. I don't want the player's key-repeat system prefs to influence the game. However, it seems sort of unresponsive because of this. Any tips on how to handle key input would be appreciated.
To rotate the shapes I tried using combined NSAffineTransforms that first translated the origin to an axis-of-rotation-point, then rotated and then translated the other way. However, I didn't get it to work, and ended up defining the matrix for the transformation instead, using NSAffineTransform with that instead.
Everything worked fine until I started letting the shapes fall down. Now when I do that, and take in key events that rotate it too, the rotations start going in wide circles, and the shapes start jumping all over the place. I know this might not be expressed in the clearest possible way, but any ideas of what is going wrong would be helpful.
I'd also like to ask some advice on Timers while I'm at it. I'm using an NSTimer to step the game forward. What are the pros & cons of doing this as opposed to using a separate thread? Also I'm using keyCodes to determine what key has been pressed, not letting those events that are repeated (isARepeat) do anything, so that the player has to keep tapping keys instead of just holding one down. I don't want the player's key-repeat system prefs to influence the game. However, it seems sort of unresponsive because of this. Any tips on how to handle key input would be appreciated.