CodingTrain / CodingTrain/Suggestion-Box
Question regarding Object Communication video 7.7
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 570
- Fork
- 85
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
Hello! I have a question in regards to the final result of the object communication code found in your program at the end of the 7.7 video. The code reads like this:
`for (b of bubbles) {`
` b.show();`
` b.move();`
` let overlapping = false;`
` for (other of bubbles) {`
` if (b !== other && b.intersects(other)) {`
` overlapping = true;`
` }`
` }`
` if (overlapping) {`
` b.changeColor(255);`
` } else {`
` b.changeColor(0);`
` }`
`}`
Please forgive me if I cannot ask this question properly: How would you, in this example, reference the *other* object within the *b* object's code? For example...
Let's say I want to draw a line that is 500 pixels long from the x and y of the *b* object at a random angle outwards every frame. Now, if an *other* object is "within range", so within 500 pixels of the *b* object, then draw the line from the x and y of the *b* object to the x and y of the *other* object (now less than 500 pixels long).
In the case above, I would need to pull the x and y coordinates of the *b* object and the *other* object within the same scope. The problem that I am having is that the if statement regarding overlapping being true or false is removed from the scope of the `for (other of bubbles)` loop, and as explained in the video, is necessary to avoid the problem of only-last-object interaction. So how could you remove the *other* object from scope while also running through the for loop every frame, while simultaneously avoiding the only-last-interaction problem?
Thank you!
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Payload trỏ đến video 7.7 về Object Communication và đoạn mã cuối cùng được hiển thị ở đó; trước tiên hãy xem lại ví dụ đó và các quy tắc về phạm vi của câu hỏi. Hoàn thành nghĩa là cung cấp một phần giải thích được ghi chép, đề cập đến việc truy cập cả hai đối tượng mà không đưa trở lại vấn đề tương tác chỉ với đối tượng cuối cùng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- content
- Loại issue
- Tài liệu
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100