From Test-Scratch-Wiki

Revision as of 13:09, 6 January 2019 by Eribetra (talk | contribs) (added an a)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Translate: - English - Português - 中文 
Este artigo é sobre o bloco. Para mais informações sobre o valor que este bloco reporta, veja Posição X (valor).
Posição X
(posição x :: motion)

Tipo: Reportador
Categoria: Movimento

O bloco Posição X é um bloco de Movimento e um bloco Reportador. Este bloco informa a posição X de um ator. Este bloco pode ser exibido no Palco.

Exemplos de Uso

As this block holds its sprite's X position, it can be used when a script needs to know its sprite's X position. 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.

  wait until <(x position) > [220]>
  change [Hits v] by (1)

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 position.

set [worms v] to (x position)

Other common uses are:

  • Comparing the X position with a record to check for movement
when green flag clicked
set [x_pos prev v] to (x position)
if <not <(x_pos prev) = (x position)>> then
say [My X position moved!] for (2) secs //if the x position moved, say something
set [x_pos prev v] to (x position)
  • Constantly storing a sprite's X movement so it can be re-enacted later
when green flag clicked //script only works in a sprite!
delete (all v) of [x positions v]
delete (all v) of [y positions v]
say [Move your mouse and I will reenact the movement!] for (2) secs
say [Go!] for (1) secs
repeat (50)//records 50 coordinates at a rate of one for every 0.1 seconds
add (mouse x) to [x positions v]
add (mouse y) to [y positions v]
wait (0.1) secs
set [counter v] to [1]
say [I will reenact it for you now!] for (2) secs
repeat (50)
go to x:(item (counter) of [x positions v]) y:(item (counter) of [y positions v])
wait (0.1) secs
change [counter v] by (1)


Main article: List of Block Workarounds

The block can be simply replicated with the following block:

([x position v] of [wanted sprite v])

See Also