Saltar navegación

Activa JavaScript para disfrutar de los vídeos de la Mediateca.

Platformer01 - Contenido educativo

Ajuste de pantalla

El ajuste de pantalla se aprecia al ver el vídeo en pantalla completa. Elige la presentación que más te guste:

Subido el 5 de noviembre de 2023 por Juan Carlos A.

26 visualizaciones

Descargar la transcripción

Hello, in this video tutorial I'm going to show you a different way in which you can move your character 00:00:00
Till now we have moved our character by hitting the right arrow and left arrow keys 00:00:08
and using when, right arrow key pressed, point right and move 00:00:16
and when, left arrow key pressed, point left and move 00:00:23
and now we are going to use a different block 00:00:33
instead of using move we are going to use change the x coordinate 00:00:38
right? 00:00:46
and instead of using when, right arrow key pressed, we are going to use if 00:00:48
and under sensing, key pressed 00:00:56
if right arrow key pressed, then change x by 10 00:01:04
this has to be inside a forever 00:01:11
and this two blocks, the forever and the if, will do the same as the when, right arrow key pressed 00:01:15
why are we using this two instead of this one? 00:01:24
because we want something to be included here inside the forever 00:01:27
whenever this key or the left arrow key are not pressed 00:01:31
so I'm going to duplicate this for the left one 00:01:39
so if left arrow key pressed, change by a negative amount now 00:01:44
and this is going to be under a green flag, so it happens from the beginning 00:01:52
now what's happening here, we are not going to use those two now 00:01:59
you may imagine something is wrong after 00:02:06
this to the right and this to the left 00:02:11
now, we want it to point into the direction 00:02:15
point to the right and now point to the left 00:02:25
and now something else is going to happen 00:02:31
you may be imagining it by now 00:02:34
ok, so let's check it 00:02:39
going right and now going left is upside down 00:02:41
always because we haven't placed set rotation style left right 00:02:44
so at the beginning we set rotation style left right 00:02:50
and now it's moving right and moving left 00:02:55
let's say I also place the cat at a starting position 00:03:00
so I will drag and drop it and use the go to block 00:03:07
and now I have a motion to the right and motion to the left 00:03:13
if I want to include the animation I can do it at a separate thread like this 00:03:19
so from the beginning I use a forever and a next custom 00:03:27
and now I can use a wait here so I can control the rhythm of the animation 00:03:41
independent from the speed of the motion, let's say 0.2 00:03:49
and now this is what happens, it's animated 00:03:55
but then it's animated even though it's not moving 00:03:59
so I want this animation to happen only if I'm pressing either one of these two keys or any key 00:04:04
so I'm going to use an if 00:04:14
and again under sensing key press and I will pick here any key 00:04:17
so this will happen only when I'm hitting the keys 00:04:28
so now it's not animated, I hold down the right arrow key it's animated 00:04:37
I hold down the left arrow key it's animated 00:04:45
so till now nothing new from what we accomplished using when, right arrow, key press, point right and move 00:04:47
but I want this to be more realistic so I'm going to include some acceleration 00:04:58
so for this to accelerate this number should change 00:05:05
so for the number to change I'm going to use a variable 00:05:14
I go into variables and make a variable, I'm going to call it xSpeed 00:05:20
and I want it to be 0 at the beginning 00:05:28
and so now instead of changing the position I'm going to change the speed 00:05:39
so I will change the horizontal speed when I hit the right arrow key 00:05:48
I'm going to change it by let's say 2, you can make it go faster or slower by changing this number 00:05:57
and if going left I want to change the horizontal speed by a negative number 00:06:05
but now I'm not changing the position so it's not actually moving it's just pointing left and right 00:06:15
for the change to happen this has to be under the green flag 00:06:25
so it happens from the beginning and we want the change to happen forever 00:06:35
but we don't want the change to be just 10, we want it to be a different value 00:06:46
depending on if we hit the left or right arrow keys 00:06:56
so the change in position will be the value of the variable 00:07:03
and we change the value of the variable here by hitting the right or the left arrow keys 00:07:09
so at the beginning the xSpeed will be 0 00:07:16
if I hit the right arrow once it will become 2 00:07:22
if I hit the left one it will become, actually I hit it twice 00:07:30
if I keep it hit it, it goes faster and faster, you see 00:07:36
because it becomes 2, then 4, then 6, then 8, 10 and so on 00:07:41
and if I hold down the left arrow key it becomes 00:07:46
greater than in the negative side so it accelerates to the left 00:07:57
so now the longer I keep it the faster it goes 00:08:02
but then this is not realistic because it doesn't stop 00:08:07
so as I said before I want something to happen when I'm not hitting the keys 00:08:14
when I release my finger from the keys I want it to decelerate and stop automatically 00:08:23
so how I make the xSpeed a lesser and lesser value automatically 00:08:32
I'm going to multiply it by a number lesser than 1 00:08:42
so I go to operators and multiply 00:08:49
so if I make the xSpeed xSpeed times 0.9 it becomes a small number 00:08:53
so I'm going to set the value of the xSpeed to a new one 00:09:05
which is the previous one that made it smaller 00:09:14
and if I put it into the forever loop it will go smaller and smaller 00:09:20
so, see, we start here, it's 0, I hold down the right arrow key 00:09:28
the xSpeed will go up and as soon as I release it 00:09:37
it will start automatically to get smaller until it gets to 0 00:09:41
there it goes 00:09:47
and the same thing happens when going to the left 00:09:50
accelerates and then decelerates 00:09:54
so now it automatically decelerates and it takes a little time for it to happen 00:09:57
so it becomes so realistic 00:10:05
it accelerates and when I release the key it decelerates and stops 00:10:07
why? because imagine I hold the right key until this changes from 0 to 2 00:10:13
then to 4, 6, 8 and 10 00:10:22
and then I release the key 00:10:26
so the xSpeed is 10 and now it multiplies by 0.9 so it becomes 9 00:10:30
so in the next loop the 9 becomes 9 times 0.9 00:10:37
so 8.1 00:10:46
and then at the next cycle 8.1 times 0.9 becomes 7 point something 00:10:50
and then 7 point something times 0.9 becomes 6 point something 00:10:58
and so it decreases automatically until it stops 00:11:02
so, let's see what's in here 00:11:07
first of all, the motion is all in here 00:11:12
the position changes by the value of the xSpeed variable 00:11:16
at the beginning it's 0 00:11:21
any time we hit a right arrow this value increases 00:11:25
so if we keep it hit the xSpeed will become greater 00:11:30
and the change in x will become greater 00:11:35
so it accelerates to the right 00:11:38
same thing happens but in reverse when we hit the left key 00:11:40
if we hold it the xSpeed will decrease 00:11:46
and it will become greater than negative 00:11:51
so it will move faster to the left, accelerating to the left 00:11:55
and if we are not hitting any key 00:11:59
then the horizontal speed, the value by which the coordinate changes 00:12:03
will decrease automatically until it becomes 0 00:12:11
so it will automatically decelerate 00:12:16
and that's the new way in which you can move your character 00:12:20
while the animation is taken care of in this group here 00:12:25
and this if any key pressed will make the animation go whenever you hit any key 00:12:30
and stop if you are not hitting it 00:12:41
and that's what I wanted you to learn in this tutorial 00:12:44
thank you 00:12:49
Valoración:
  • 1
  • 2
  • 3
  • 4
  • 5
Eres el primero. Inicia sesión para valorar el vídeo.
Idioma/s:
en
Autor/es:
Juan carlos Alonso de Mena
Subido por:
Juan Carlos A.
Licencia:
Reconocimiento - No comercial
Visualizaciones:
26
Fecha:
5 de noviembre de 2023 - 11:05
Visibilidad:
Público
Centro:
IES ALPEDRETE
Duración:
12′ 50″
Relación de aspecto:
16:10 El estándar usado por los portátiles de 15,4" y algunos otros, es ancho como el 16:9.
Resolución:
1920x1200 píxeles
Tamaño:
39.47 MBytes

Del mismo autor…

Ver más del mismo autor


EducaMadrid, Plataforma Educativa de la Comunidad de Madrid

Plataforma Educativa EducaMadrid