Nội dung bài họcLesson content
Clone là gì?What is a clone?
Clone là bản sao của một sprite. Thay vì thêm 50 sprite trái cây thủ công, bạn tạo 1 sprite rồi clone 50 lần. Mỗi clone hoạt động độc lập nhưng chia sẻ cùng code. Clone giúp game có nhiều vật thể mà không cần duplicate code.A clone is a copy of a sprite. Instead of manually adding 50 fruit sprites, you create 1 sprite and clone it 50 times. Each clone acts independently but shares the same code. Clones let games have many objects without duplicating code.
Tạo clone trong ScratchCreating clones in Scratch
Dùng khối "create clone of [myself]" để tạo bản sao của sprite hiện tại. Dùng "create clone of [sprite]" để clone sprite khác. Mỗi clone sẽ chạy khối "when I start as a clone" — đây là điểm bắt đầu của clone.Use "create clone of [myself]" to create a copy of the current sprite. Use "create clone of [sprite]" to clone another sprite. Each clone runs the "when I start as a clone" block — this is the clone's starting point.
when flag clicked
forever
create clone of [myself]
wait 1 seconds
when I start as a clone
go to random position
glide 2 secs to y: -180
if <touching basket?> then
change [điểm] by [1]
delete this clone
Xóa cloneDeleting clones
Mỗi clone cần được xóa khi không còn cần, nếu không game sẽ chậm. Dùng khối "delete this clone" khi clone chạm giỏ hoặc chạm đáy màn hình. Nếu không xóa, hàng nghìn clone sẽ tích lũy và làm game lag.Each clone needs to be deleted when no longer needed, otherwise the game will slow down. Use "delete this clone" when the clone touches the basket or the bottom of the screen. If not deleted, thousands of clones will accumulate and lag the game.
Game bắn bóng: ứng dụng cloneBubble shooter game: clone application
Trong game bắn bóng, mỗi viên đạn là 1 clone. Khi nhấn phím space, tạo clone đạn bay lên. Khi đạn chạm bóng → xóa đạn + xóa bóng + tăng điểm. Clone giúp bắn nhiều đạn cùng lúc mà không cần sprite riêng cho mỗi viên.In a bubble shooter game, each bullet is a clone. When you press space, create a bullet clone that flies up. When the bullet touches a bubble → delete bullet + delete bubble + increase score. Clones let you fire many bullets at once without separate sprites.