How to Move Sprites with the Arrow Keys: различия между версиями
Материал из Поле цифровой дидактики
Patarakin (обсуждение | вклад) м (1 версия импортирована) |
Patarakin (обсуждение | вклад) |
||
Строка 1: | Строка 1: | ||
{{Scripting Tutorials | |||
|Description=Как управлять спрайтами при помощи клавиш клавиатуры | |||
|Field_of_knowledge=Информатика | |||
|FieldActivity=Дизайнер Сообществ | |||
|Возрастная категория=7 | |||
|Environment=Scratch | |||
}} | |||
This tutorial explains how one can make a [[game]] or interactive [[animation]] that '''moves sprites with the arrow keys'''. | This tutorial explains how one can make a [[game]] or interactive [[animation]] that '''moves sprites with the arrow keys'''. | ||
Версия 15:27, 30 августа 2022
Описание | Как управлять спрайтами при помощи клавиш клавиатуры |
---|---|
Область знаний | Информатика |
Область использования (ISTE) | Дизайнер Сообществ |
Возрастная категория | 7
|
Поясняющее видео | |
Близкие рецепту понятия | |
Среды и средства для приготовления рецепта: | Scratch |
This tutorial explains how one can make a game or interactive animation that moves sprites with the arrow keys.
X-Y Method
This is the easiest way to do this. First, go to the sprite you want to make move. Then, add these scripts:
when [up arrow v] key pressed change y by (10) when [down arrow v] key pressed change y by (-10) when [right arrow v] key pressed change x by (10) when [left arrow v] key pressed change x by (-10)
The sprite will move when the arrow keys are pressed however it will point the same direction.
Steps Method
Using these scripts, the sprite will turn around while it moves. This is not recommended in a sprite that must turn for other reasons.
when [up arrow v] key pressed point in direction (0) move (10) steps when [down arrow v] key pressed point in direction (180) move (10) steps when [right arrow v] key pressed point in direction (90) move (10) steps when [left arrow v] key pressed point in direction (-90) move (10) steps
Now your sprite will turn when it moves.
Loop Method
Both methods above can also be written as such below (note in this example the X-Y method is used but the steps method will work with this code too if changing direction is desired):
when gf clicked forever if <key (up arrow v) pressed?> then change y by (10) end if <key (down arrow v) pressed?> then change y by (-10) end if <key (right arrow v) pressed?> then change x by (10) end if <key (left arrow v) pressed?> then change x by (-10) end