tailieunhanh - ActionScript 3.0 Game Programming University, Second Edition phần 2
Trước khi chúng tôi xây dựng hoàn thành trò chơi, chúng tôi bắt đầu với một số mảnh nhỏ hơn. Các chương trình ngắn trong chương này cho chúng ta một cái nhìn tại một số khái niệm cơ bản ActionScript 3,0 và cũng có thể cung cấp cho chúng tôi với một số khối xây dựng để sử dụng sau này và trong các trò chơi của riêng bạn. | 36 Chapter 2 ActionScript Game Elements Before we build complete games we start with some smaller pieces. The short programs in this chapter give us a look at some basic ActionScript concepts and also provide us with some building blocks to use later and in your own games. Source Files http Creating Visual Objects Our first few elements involve the creation and manipulation of objects on the screen. We pull some movie clips from the library turn movie clips into buttons draw some shapes and text and then learn to group items together in sprites. Using Movie Clips When you ve got a movie clip in the library and want to bring it into your game there are two ways to do it. The first way is to drag and drop the movie clip onto the stage and give it an instance name in the Property Inspector. Figure shows a movie clip moved from the library to the stage and then named myCliplnstance in the Properties Inspector. Figure The movie clip object is named Mascot in the library but the instance of the movie clip on the stage is named myClipInstance. Then you can manipulate the properties of the movie clip by referring to it by name like this 300 200 Wow eBook Creating Visual Objects 37 The second way to bring a movie clip into your game uses purely ActionScript code. But first you must set the movie clip to be accessible by setting its Linkage properties. To do this simply click in the Linkage column you can see on the right side of the Library list. In Figure the name Mascot has already been placed there. I usually set the class name the same as the movie clip name. It makes it easier to remember. Now we can create new copies of the movie clip using only ActionScript. The way this is done is to create a variable to hold the instance of the object and then use addChild to put it in a display list var myMovieClip Mascot new Mascot addChild myMovieClip The variable named .
đang nạp các trang xem trước