TAILIEUCHUNG - ActionScript 3.0 Game Programming University, Second Edition phần 4

Khi bạn đã có một đoạn phim trong thư viện và muốn mang lại cho nó thành trò chơi của bạn, có hai cách để làm điều đó. Cách thứ nhất là kéo và thả các đoạn phim lên sân khấu và cung cấp cho nó một cái tên thể hiện trong Thanh tra Sở hữu. Hình cho thấy một đoạn phim di chuyển từ thư viện sân khấu, | 154 Chapter 5 Game Animation Shooting and Bouncing Games If we made the object move 100 pixels every frame it would be at 300 pixels out having gotten only three frames to move. This could be different on another computer or at another time on the same computer when performance was good enough to deliver four frames per second. Coding Time-Based Animation The trick to coding time-based animation is to keep track of the time. By looking at the function getTimer you can get the number of milliseconds since the movie started. The actual value of getTimer isn t important. It is the difference in time between frames that matters. For instance it might take 567 milliseconds for your movie to initialize and place items on the screen. The first frame happens at 567 milliseconds and the second frame at 629. The difference is 62 milliseconds which is what we need to know to determine how far an object has moved between the frames. The movie contains a simple circle movie clip to demonstrate timebased animation. The movie uses as its main script and as the class for the movie clip. The AnimatedObject class has a constructor function that accepts parameters. This means that when you create a new AnimatedObject you must pass parameters in like this var myAnimatedObject AnimatedObject new AnimatedObject 100 150 5 -8 The four parameters represent the horizontal and vertical location of the movie clip plus the horizontal and vertical speed of the movie clip. Here is the class declaration variable declarations plus the AnimatedObject function. You can see the four parameters defined simply as x y dx dy package import . import . import public class AnimatedObject extends MovieClip private var speedX speedY Number current speed pixels per second private var lastTime int remember the last frame s time public function AnimatedObject x y dx dy set location and speed x y .

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.