| MetaCard y Revolution: Herramientas de autor multiplataforma para multimedia | ||
|---|---|---|
| Anterior | Capítulo 10. Vídeo y animación | Siguiente |
Activitats relatives al àmbit de Multimedia on el moiment siga una peça clau: bé siga per l'animación de imatgens i/o gràfics o per la sucesió d'imatgens fixes, siguen el principal encant.
Castell de focs artificials.
Antiestrés 2: divertiment que permet menejar, pintar y "destroçar" els continguts de la pantalla.
Punts de sincronisme en la banda d'audio: QuickTime? pot extraure-los. Alternatives?
Streaming, vídeo interactivo, ...
Se propone realizar un castillo de fuegos artificiales, con una limitación: los elementos visibles han de ser puntos, estos deberán exhibir colores y movimientos que recuerden el de los cohetes que componen una típica mascletà.
La aproximación que se muestra aquí, es incremental con lo que se quiere:
Introducir al lector en la solución planteada poco a poco, mostrando los puntos comunes y el mecanismo común.
Dejar abierto el tema lo suficiente para que el lector plantee una continuación propia, o lo que sería más interesante: un editor de cohetes y de mascletàs para facilitat posteriores desarrollos.
Sugerencia: En esta línea y en una tercera etapa se puede pensar en realizar un "castillo piromusical", esto es aquel en que la música y los fuegos artificiales tienen una relación que se podría concretar en dependencia de los valores de los segundos con los cambios de la primera, por ejemplo a partir de un fichero MIDI .
Por una parte, las cosas comunes ... La situación de los objetos en la ventana y la de esta misma, se controla con el código de la pila y el de la tarjeta. Así como se ha dispuesto un botón para reiniciar la secuencia.
# stack ""
on preOpenStack
set the decorations of this stack to zero
set the location of this stack to screenLoc()
end preOpenStack
#card "castellDeFoc"
on openCard
repeat with numero = 1 to the number of groups of this card
set the location of graphic ("cuet" & numero) of group ("cuet" & numero) to the posicioInicial of \
graphic ("cuet" & numero) of group ("cuet" & numero)
--260,460
send "mostrat" to group ("cuet" & numero)
-- ask "mostrar group" && ("cuet" & numero)
end repeat
send "encendreLaMetxa"
end openCard
on encendreLaMetxa
repeat with numero = 1 to the number of groups of this card
send "muevete" to group ("cuet" & numero) in \
(the tempsInici of graphic ("cuet" & numero) of \
the group ("cuet" & numero)) milliseconds
end repeat
end encendreLaMetxa
# on keyUp
# send "mouseUp" to me
# end keyUp
# button "Sr. pirotecnic, pot ..."
on mouseUp
send "openCard" to this card
end mouseUp
Por otra, veamos una primera aproximación: el más sencillo de todas las "carcasas" ... Para guardar las propiedades de cada cohete se han empleado una serie de propiedades privadas del objeto que lo implementa, en este caso del objeto "graphic". El listado completo de propiedades del objeto graphic "cuet1" incluye:
La posición final que alcanzará el objeto viene dada por altura, que guarda el valor relativo a la posición de partida hasta donde se ha de desplazar. En este caso vale 50, que en términos de la orden move son píxeles.
coloret: 0,255,0 o lo que es lo mismo "verde".
numFills: 0
posicioInicial: 60,460
sonitEsclatar, el primero que hemos encontrado que tiene cierta relación y cuyo formato es aceptado por MetaCard: boom.wav
El punto temporal en milisegundos, desde el comienzo del "castillo", se establece on tempsInici a 10.
Figura 10-10. Ventana de propiedades del objeto grahic "cuet1" donde se puede observar las propiedades que se utilizan y el valor de la primera de ellas.

#group "cuet1"
on mostrat
repeat with numero = 1 to \
the numFills of graphic (the short name of me) of group (the short name of me)
hide graphic (the short name of me & "_fill" & numero)
end repeat
show graphic (the short name of me)
end mostrat
on muevete
send muevete to graphic (the short name of me) of group (the short name of me) in \
(the tempsInici of graphic (the short name of me) of\
group (the short name of me) ) milliseconds
end muevete
#graphic "cuet1"
on muevete
if the visible of me is not true then exit "muevete"
# Si es pot, avant: puja amunt i quant aplegues dalt esclata
if ( the second item of the location of me = \
(the second item of the posicioInicial of me - the altura of me) )
then
-- put "Plof"
play "sons/" & the sonitEsclatar of me
hide me
else
set the location of me to the first item of (the location of me), \
the second item of (the location of me) - 1
send "muevete" to me in 100 milliseconds
end if
end muevete
Un paso más: añadamos la posibilidad de que al terminar la carcasa incial, aparezcan nuevos elementos ("hijos") ...
Para ello, será necesario cambiar los parámetros de comportamiento del graphic "cuet2", que como se han expuesto para el caso anterior, ahora son:
Para que suba algo más que el anterior, establecermos la altura a un valor superior, por ejemplo 80.
Un color diferente, por ejemplo magenta, concoloret igual a 255,0,255.
Este ya tendrá "hijos", así que empecemos poco a poco y utilicemos un valor de numFills de 2.
Que estará situado en un punto diferente de la mascletà, digamos que posicioInicial le asignamos un valor algo más a la la derecha como "100,460".
El sonido no es necesario cambiarlo en este caso, así que sonitEsclatar sigue conteniendo boom.wav.
Y para secuenciarlos en el tiempo, incializaremos tempsInici1000. Vamos que este irá un poco después.
#group "cuet2"
on mostrat
-- ask (the tempsInici of graphic (the short name of me) of\
-- the group (the short name of me))
# send "muevete" to me in \
# (the tempsInici of graphic (the short name of me) of
# the group (the short name of me)) milliseconds
end mostrat
on muevete
set the firstcolor of graphic (the short name of me) to\
(the coloret of graphic (the short name of me))
repeat with numero = 1 to \
the numFills of graphic (the short name of me) of\
the group (the short name of me)
hide graphic (the short name of me & "_fill" & numero)
-- ask "ocultar " && (the short name of me & "_fill" & numero)
set the firstcolor of graphic (the short name of me & "_fill" & numero) to \
(the coloret of graphic (the short name of me))
end repeat
show graphic (the short name of me)
-- show graphic (the short name of me)
send muevete to graphic (the short name of me) of the group (the short name of me)
end muevete
#graphic "cuet2"
on muevete
if the visible of me is not true then exit "muevete"
# Si es pot, avant: puja amunt i quant aplegues dalt esclata
if ( the second item of the location of me = \
(the second item of the posicioInicial of me - the altura of me) )
then
-- put "Plof"
play "sons/" & the sonitEsclatar of me
hide me
repeat with numero = 1 to the numFills of me
-- ask "menejat" && (the short name of me & "_fill" & numero)
send ("muevete" && the location of me) to \
the graphic (the short name of me & "_fill" & numero) of\
group (the short name of me)
end repeat
else
set the location of me to the first item of (the location of me), \
the second item of (the location of me) - 1
send "muevete" to me in 100 milliseconds
end if
end muevete
#graphic "cuet2_fill1"
on muevete posX, posY
-- ask posX && posY
# Posicionat
set the location of me to (posX + the first item of the posicioInicial of me), \
(posY + the second item of the posicioInicial of me)
show me
send ("menejat" && posY) to me
end muevete
on menejat posY
-- ask valorY && (valorY + the altura of me)
-- put "[" & posY &"," & (posY + the altura of me) &"]" && the location of me && "(" && \
--the second item of the location of me && "=" && (posY + the altura of me) && ")"
if the visible of me is not true then exit "menejat"
# Si es pot, avant: ves baixant i quant aplegues desapareix
if ( the second item of the location of me = (posY + the altura of me) )
then
hide me
else
set the location of me to the first item of (the location of me), \
the second item of (the location of me) + 1
send ("menejat" && posY) to me in 100 milliseconds
end if
end menejat
#graphic "cuet2_fill2"
on muevete posX, posY
# Posicionat
set the location of me to (posX + the first item of the posicioInicial of me), \
(posY + the second item of the posicioInicial of me)
show me
send ("menejat" && posY) to me
end muevete
on menejat posY
if the visible of me is not true then exit "menejat"
# Si es pot, avant: ves baixant i quant aplegues desapareix
if ( the second item of the location of me = (posY + the altura of me) )
then
hide me
else
set the location of me to the first item of (the location of me), \
the second item of (the location of me) + 1
send ("menejat" && posY) to me in 100 milliseconds
end if
end menejat
Sólo queda ir complicando un poco más el movimiento de cada uno de los "cohetes", esto se puede hacer aprovechando la estructura anterior y ...
#group "cuet3"
on mostrat
-- ask (the tempsInici of graphic (the short name of me) of\
-- the group (the short name of me))
# send "muevete" to me in \
# (the tempsInici of graphic (the short name of me) of\
# the group (the short name of me)) milliseconds
end mostrat
on muevete
set the firstcolor of graphic (the short name of me) to\
(the coloret of graphic (the short name of me))
repeat with numero = 1 to the numFills of\
graphic (the short name of me) of the group (the short name of me)
hide graphic (the short name of me & "_fill" & numero)
-- ask "ocultar " && (the short name of me & "_fill" & numero)
set the firstcolor of graphic (the short name of me & "_fill" & numero) to\
(the coloret of graphic (the short name of me))
end repeat
show graphic (the short name of me)
-- show graphic (the short name of me)
send muevete to graphic (the short name of me) of the group (the short name of me)
end muevete
#graphic "cuet3"
on muevete
if the visible of me is not true then exit "muevete"
# Si es pot, avant: puja amunt i quant aplegues dalt esclata
if ( the second item of the location of me = \
(the second item of the posicioInicial of me - the altura of me) )
then
-- put "Plof"
play "sons/" & the sonitEsclatar of me
hide me
repeat with numero = 1 to the numFills of me
-- ask "menejat" && (the short name of me & "_fill" & numero)
send ("muevete" && the location of me) to \
the graphic (the short name of me & "_fill" & numero) of group (the short name of me)
end repeat
else
set the location of me to the first item of (the location of me), \
the second item of (the location of me) - 1
send "muevete" to me in 100 milliseconds
end if
end muevete
#graphic "cuet3_fill1"
on muevete posX, posY
-- ask posX && posY
# Posicionat
set the location of me to (posX + the first item of the posicioInicial of me), \
(posY + the second item of the posicioInicial of me)
show me
send ("menejat" && posY) to me
end muevete
on menejat posY
-- ask valorY && (valorY + the altura of me)
-- put "[" & posY &"," & (posY + the altura of me) &"]" && the location of me && "(" && \
--the second item of the location of me && "=" && (posY + the altura of me) && ")"
if the visible of me is not true then exit "menejat"
# Si es pot, avant: ves baixant i quant aplegues desapareix
if ( the second item of the location of me = (posY + the altura of me) )
then
hide me
else
set the location of me to (the first item of (the location of me) + 1), \
the second item of (the location of me) + 1
send ("menejat" && posY) to me in 100 milliseconds
end if
end menejat
#graphic "cuet3_fill2"
on muevete posX, posY
# Posicionat
set the location of me to (posX + the first item of the posicioInicial of me), \
(posY + the second item of the posicioInicial of me)
show me
send ("menejat" && posY) to me
end muevete
on menejat posY
if the visible of me is not true then exit "menejat"
# Si es pot, avant: ves baixant i quant aplegues desapareix
if ( the second item of the location of me = (posY + the altura of me) )
then
hide me
else
set the location of me to (the first item of (the location of me) -1), \
the second item of (the location of me) + 1
send ("menejat" && posY) to me in 100 milliseconds
end if
end menejat