From Test-Scratch-Wiki
X 座標 | |
(X 座標) | |
類別 | 動作類積木 |
形狀 | 橢圓形積木 |
The x座標 積木 is a 動作類積木 and a 橢圓形積木. The block holds its 角色的 x座標. This block can be displayed as a 舞台監控視窗.
用法示例
As this block holds its sprite's x座標, it can be used when a script needs to know its sprite's x座標. There are many cases of this — for example, you could use the block to detect how far left or right you are on the screen.
重複無限次 等待直到 <(x座標) > [220]> 變數 [Hits v] 改變 (1) end
Another use is setting values based on a movable slider without using Scratch's default slider — the script sets the value to the slider's x座標.
變數 [worms v] 設為 (x 座標)
Other common uses are:
- Comparing the x座標 with a record to check for movement
當 @greenflag 被點擊 變數 [x_pos prev v] 設為 (x 座標) 重複無限次 如果 <<(x_pos prev) = (x座標)> 不成立> 那麼 說出 [My xpostion moved!] (2) 秒 // if the x座標 moved, say something 變數 [x_pos prev v] 設為 (x 座標) end end
- Constantly storing a sprite's X movement so it can be re-enacted later
當 @greenflag 被點擊 // script only works in a sprite! 刪除第 (全部 v) 項 \( [x座標s v] \) 刪除第 (全部 v) 項 \( [y 座標s v] \) 說出 [Move your mouse and I will reenact the movement!] (2) 秒 說出 [Go!] (1) 秒 重複 (50) 次 新增項目 (滑鼠游標的 x) \( [x座標s v] \) 新增項目 (滑鼠游標的 y) \( [y 座標s v] \) 等待 (0.1) 秒 end // records 50 coordinates at a rate of one for every 0.1 seconds 變數 [counter v] 設為 [1] 說出 [I will reenact it for you now!] (2) 秒 重複 (50) 次 定位到 x: (清單第 (counter) 項項目\( [x座標s v] \) :: list) y: (清單第 (counter) 項項目\( [y 座標s v] \) :: list) 等待 (0.1) 秒 變數 [counter v] 改變 (1) end
- Changing a sprite's speed based on its 坐標系統
應用
- Main article: List of Block Workarounds
The block can be simply replicated with the following block:
([x座標 v] \( [wanted sprite v] \))