TAILIEUCHUNG - iPhone Cool Projects phần 7

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 2 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 .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.