Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Chúng tôi không xử lý bất kỳ cử chỉ cho ba hoặc nhiều ngón tay, vì vậy chúng tôi lọc ra khỏi đầu. Không có lý do gì bạn không thể thêm xử lý của riêng bạn ở đây, ít nhất, không có lý do kỹ thuật. Cho dù đó là nên hay không phải từ góc độ người dùng kinh nghiệm là một câu hỏi khác. Vì vậy, đây là cách chúng tôi xử lý một cử chỉ hai ngón tay: | 118 CHAPTER 5 Physics Sprites and Animation with the cocos2d-iPhone Framework Finally we add the shape to the space so it will show up on our main layer. @end int puckHitPusher cpShape a cpShape b cpContact contacts int numContacts cpFloat normal_coef void data GameLayer mainLayer pushPuckFromCorner return 0 Our C function callback simply forwards the message on to the main layer and pushes the puck out from the corner. Simulating 3D Lighting in 2D Space To simulate realistic lighting on the mallets we resorted to a classic trick. If we center the light on the table we can fake the direction of the light by rotating the mallets based on their position relative to the center as shown in Figure 5-6 . This will make the mallets highlights and shadows appear to respond realistically to the light. Figure 5-6. The minigolf game layer with player sprites rotated based on their angles to the center CHAPTER 5 Physics Sprites and Animation with the cocos2d-iPhone Framework 119 In Listing 5-3 you ll learn how to rotate sprites relative to the center of the playing area to simulate a central light source. Listing 5-3. 3D Lighting Simulation - void step ccTime delta snip. handle the rotation of the pucks to emulate the effect of a light source cpVect newPosition find the center of the stage CGRect wins Director sharedDirector winSize cpVect centerPoint cpv wins.size.width 2 wins.size.height 2 rotate player 1 newPosition cpvsub centerPoint player1- p Sprite p1_shape- data setRotation 90 - RADIANS_TO_DEGREES cpvtoangle newPosition rotate player 2 newPosition cpvsub centerPoint player2- p Sprite p2_shape- data setRotation 90 - RADIANS_TO_DEGREES cpvtoangle newPosition We first find the center of the stage by cutting the main window s width and height in half. For each player we subtract the mallet s position from the center point and use that to calculate the angle with cpvtoangle using the result to set the rotation of the sprite. We call the standard OpenGL RADIANS_TO_DEGREES .