Anuncios Google

[SOLUCIONADO] Pregunta dificil de matematicas.

Hola. Esta pregunta es complicada, al menos eso creo...

x--xdestino--velocidadx
y--ydestino--velocidady

w--wdestino--velocidadw
h--hdestino--velocidadh

Necesito saber una formula para que:
x e y llegue a xdestino e ydestino a la vez que w y h llegue a wdestino y hdestino con la velocidad que sea necesaria. Con velocidad me refiero a repetir un numero (velocidad) las veces que sean necesarias.

Necesito saber la formula para hallar velocidadw y velocidadh.

Quizás no halla una formula posible para esto, pero no lo se. Si alguien lo sabe, le recompensaré con 5 estrellas al que me de la formula para hallar velocidadw y velocidadh.

TODAS las variables PUEDEN ser CUALQUIER NUMERO.

Muchas gracias por adelantado.




EDITO: Un problema.

Ahora se desplaza pero en vez de reducir su tamaño lo aumenta y no para de aumentar... a ver si sabeis por qué...

thunder = {img = image.load("Recursos/img.png"),x=480/2,y=272/2,a=255}
fondo = image.create(480,272,color.new(89,189,23))
 
thunder.w = thunder.img:width()
thunder.h = thunder.img:height()
thunder.img:center()
 
while true do
controls.read()
fondo:blit(0,0)
thunder.img:blit(thunder.x,thunder.y)
	if zoom == true then
		thunder.x = thunder.x + (480/2 - thunder.x)/10
		thunder.y = thunder.y + (50 - thunder.y)/10
		thunder.w = thunder.w + (thunder.w+100 - thunder.w)/10
		thunder.h = thunder.h + (thunder.h+100 - thunder.h)/10
		image.resize(thunder.img,thunder.w,thunder.h)
	end
	if controls.press("cross") then
		fondo:blit(0,0)
		zoom = true
	end
	if controls.select() and controls.start() then
		dove()
	end
	screen.flip()
end
 

Gracias.




EDITO 2: http://psp.scenebeta.com/node/82255#comment-677653


 

 


Anuncios Google

Opciones de visualización de comentarios

Seleccione la forma que prefiera para mostrar los comentarios y haga clic en «Guardar las opciones» para activar los cambios.
Imagen de Dioni0396

prueba esto

thunder = {img = image.load("Recursos/img.png"),x=480/2,y=272/2,a=255}
fondo = image.create(480,272,color.new(89,189,23))
 
thunder.w = thunder.img:width()
thunder.h = thunder.img:height()
thunder.img:center()
 
while true do
controls.read()
fondo:blit(0,0)
thunder.img:blit(thunder.x,thunder.y)
	if zoom == true then
		thunder.x = thunder.x + (480/2 - thunder.x)/10
		thunder.y = thunder.y + (50 - thunder.y)/10
		thunder.w = thunder.w - (thunder.w+100 - thunder.w)/10
		thunder.h = thunder.h - (thunder.h+100 - thunder.h)/10
		image.resize(thunder.img,thunder.w,thunder.h)
	end
	if controls.press("cross") then
		fondo:blit(0,0)
		zoom = true
	end
	if controls.select() and controls.start() then
		dove()
	end
        if controls.circle() then
zoom = false
end
	screen.flip()
end

Ahora reducira y cuando pulses Circulo parara

Eso ya lo conseguí hace mucho...

Lo que querría saber ahora es esto.

Imagen de Chimecho

no se que haces

los valores de incremento deben ser CONSTANTES y tu estas poniendo las mismas variables que cambian con un par de cálculos para el incremento. Sigue este algoritmo para todas tus variables:

incremento = (final - inicio)/veces_que_pasara_tu_bucle

luego que tienes FIJO el incremento, dentro de un bucle sumas ese incremento



PSP FAT [5.00 M33-6] [6.60 ME] [Hard Moded] / Nintendo Wii [4.1U] [cIOS Hermes] [D2X cIOS] / iPhone 3G [4.2.1] [BB 05.13.04] [redsn0w] / iPod Touch 4 [6.1] [evasi0n]

07/05/10: Tuve el placer de llamarle con todo derecho "N00B" a molotovi xDDD

Recuerda: Sé el intérprete -_-

Ya lo he conseguido.

Ahora sale. ¿Pero sería posible hacer una funcion con estos mismos if's para no tener que estar matandote de calculos?

thunder = {img = image.load("Recursos/img.png"),x=480/2,y=272/2,a=255}
fondo = image.create(480,272,color.new(89,189,23))
 
thunder.w = thunder.img:width()
thunder.h = thunder.img:height()
thunder.ww = thunder.img:width()
thunder.hh = thunder.img:height()
velw = (51-thunder.w)/10
velh = (83-thunder.h)/10
thunder.img:center()
 
while true do
controls.read()
fondo:blit(0,0)
thunder.img:blit(thunder.x,thunder.y)
	if zoom == true then
		thunder.x = thunder.x + (480/2 - thunder.x)/10
		thunder.y = thunder.y + (50 - thunder.y)/10
		thunder.w = thunder.w + velw
		thunder.h = thunder.h + velh
		image.resize(thunder.img,thunder.w,thunder.h)
		if thunder.w <= 51 then thunder.w = 51 end
		if thunder.h <=83 then thunder.h = 83 end
	end
	if controls.press("cross") then
		fondo:blit(0,0)
		zoom = true
	end
	if controls.select() and controls.start() then
		dove()
	end
	screen.flip()
end

Gracias.

Un saludo.


 

 

Imagen de User170294

Creo que te ayudaría bastante

Creo que te ayudaría bastante usar sentencias "switch".

No existen en LuaDev que yo sepa.

No existen en LuaDev que yo sepa.

Imagen de Dioni0396

switch existe en lua

?

Imagen de Dioni0396

Te refieres a esto?

function zoom(a)
		a.x = a.x + (480/2 - a.x)/10
		a.y = a.y + (50 - a.y)/10
		a.w = a.w + velw
		a.h = a.h + velh
		image.resize(a.img,a.w,a.h)
		if a.w <= 51 then a.w = 51 end
		if a.h <=83 then a.h = 83 end
	end
--cargas una imagen con la x,y,w,h, y la imagen
--otra imagen
while true do
--bla bla
zoom(Puntero)
zoom(OtroPuntero)
end

No, digo para que...

Al usar controls.press("cross") por ejemplo se haga eso. Pero si lo hago así, solo lo hace una vez por cada pulsada, y yo quiero que lo haga de seguido y la unica forma de hacer eso es con booleanas.

Entonces: como puedo diseñar una funcion para saltarse esas booleanas (es decir, que la propia funcion tenga las booleanas).

Un saludo.


 

 

Imagen de Dioni0396

Hum....

Te diseño otra funcion haber que te parece.

Valor = false
function zoom(a,Valor2)
                Valor = Valor2
                if Valor==true then
		a.x = a.x + (480/2 - a.x)/10
		a.y = a.y + (50 - a.y)/10
		a.w = a.w + velw
		a.h = a.h + velh
		image.resize(a.img,a.w,a.h)
		if a.w <= 51 then a.w = 51 end
		if a.h <=83 then a.h = 83 end
                end
--Y aqui tu ya haces que cuando pase unos pixeles se pare.
	end
--cargas una imagen con la x,y,w,h, y la imagen
--otra imagen
while true do
--bla bla
zoom(Puntero,true)
zoom(OtroPuntero,false)
end

Yo ya, creo que te estoy confundiendo...

No. Lo entiendo...

Lo entiendo, no te preocupes... bien, voy a probar.

EDITO: no funciona.

Imagen de sting18

Reducir es poner menos "-"

Reducir es poner menos "-" para aumentar es poner mas "+"

Imagen de sting18

Sera que lo que quieras hacer

Sera que lo que quieras hacer es dar un efecto de 3D en 2D agarrando las imagenes desde atras(por asi decirlo) y se vallan acercando a a la pantalla?


No.

Quiero hacer que a la vez que se desplaza una imagen aumente de tamaño gradualmente, no de un tirón...

Imagen de sting18

es lo mismo XD ok se me

es lo mismo XD ok se me ocurre algo asi.

imagen = image.load("imagen.png")
 
efecto_imagen={}
efecto_imagen[1]={x=235,y=135,tx=10,ty=10,i=imagen}
 
image.resize(efecto_imagen[1].i,efecto_imagen[1].tx,efecto_imagen[1].ty) -- reescala la imagen al tamaño deseado
 
function efecto()
efecto_imagen[1].tx = efecto_imagen[1].tx +1 -- cambia el tamaño de imagen X
efecto_imagen[1].ty = efecto_imagen[1].ty +1 -- cambia el tamaño de imagen y
if efecto_imagen[1].tx > 450 then -- si el tamaño X es mayor a 450 entonces
efecto_imagen[1].tx=10 -- vuelves a poner el tamaño de inicio X
efecto_imagen[1].ty=10 -- vuelves a poner el tamaño de inicio y
efecto_imagen[1].x=235 -- Vuelves a poner la posicion X de inicio
efecto_imagen[1].y=135 -- Vuelves a poner la posicion Y de inicio
end
image.resize(efecto_imagen[1].i,efecto_imagen[1].tx,efecto_imagen[1].ty) -- estar marcando el reescalado todo el tiempo
efecto_imagen[1].x = efecto_imagen[1].x - 0.5 -- posicion X para centrar el aumento
efecto_imagen[1].y = efecto_imagen[1].y - 0.5 -- posicion Y para centrar el aumento
image.blit(efecto_imagen[1].x,efecto_imagen[1].y,efecto_imagen[1].i) -- Mostrar Imagen
end

Ya solo tu as las amedidas a como tu quieras espero te sirva saludos.


Imagen de DeViaNTe

como bien ha puesto

como bien ha puesto chime...

tiempo = 1.2
veces = tiempo / 60
incrementox = ( xdest-xinicio ) / veces
incrementoy = ( ydest-yinicio ) / veces
incrementow = ( wdest-winicio ) / veces
incrementoh = ( hdest-hinicio ) / veces

y en cada pasada...

x = x + incrementox;
y = y + incrementoy;
w = w + incrementow;
h = h + incrementoh;


Actualmente desarrollando nuestra web y UXCode : http://www.gcrew.es

Vale, con x e y me va...

Pero con w y h no cambia de tamaño... es width y height de una imagen.

A ver si sabeis como se hace con width y height, porque con x e y me va perfecto...

Un saludo.


 

 

Imagen de Chimecho

?

tu_imagen:resize(w, h)

Pero no me va a la vez que se desplaza la imagen...

Ademas, quiero que el aumento sea gradual, no de un tirón...

Imagen de Chimecho

pues

tu_imagen:resize(w,h) xD

si le pasas correctamente las variables, debería funcionar, así como tienes el

x = x + velx
y = y + vely

aumentas w y h:

x = x + velx
y = y + vely
w = w + velw
h = h + velh

y luego de esas sumas pones el resize, y se hará gradualmente porque el valor cambia gradualmente, claro que si pones el flip luego del while, se verá como que se resizea de un tirón y no paso a paso, para eso, mete el flip en el while...



PSP FAT [5.00 M33-6] [6.60 ME] [Hard Moded] / Nintendo Wii [4.1U] [cIOS Hermes] [D2X cIOS] / iPhone 3G [4.2.1] [BB 05.13.04] [redsn0w] / iPod Touch 4 [6.1] [evasi0n]

07/05/10: Tuve el placer de llamarle con todo derecho "N00B" a molotovi xDDD

Recuerda: Sé el intérprete -_-

No sale...

EDITO: Un problema.

Ahora se desplaza pero en vez de reducir su tamaño lo aumenta y no para de aumentar... a ver si sabeis por qué...

thunder = {img = image.load("Recursos/img.png"),x=480/2,y=272/2,a=255}
fondo = image.create(480,272,color.new(89,189,23))
 
thunder.w = thunder.img:width()
thunder.h = thunder.img:height()
thunder.img:center()
 
while true do
controls.read()
fondo:blit(0,0)
thunder.img:blit(thunder.x,thunder.y)
	if zoom == true then
		thunder.x = thunder.x + (480/2 - thunder.x)/10
		thunder.y = thunder.y + (50 - thunder.y)/10
		thunder.w = thunder.w + (thunder.w+100 - thunder.w)/10
		thunder.h = thunder.h + (thunder.h+100 - thunder.h)/10
		image.resize(thunder.img,thunder.w,thunder.h)
	end
	if controls.press("cross") then
		fondo:blit(0,0)
		zoom = true
	end
	if controls.select() and controls.start() then
		dove()
	end
	screen.flip()
end

Es decir, hacer esto:

if zoom == true then
		thunder.x = thunder.x + (480/2 - thunder.x)/10
		thunder.y = thunder.y + (50 - thunder.y)/10
		thunder.w = thunder.w + (thunder.w+100 - thunder.w)/10
		thunder.h = thunder.h + (thunder.h+100 - thunder.h)/10
		image.resize(thunder.img,thunder.w,thunder.h)
	end
	if controls.press("cross") then
		fondo:blit(0,0)
		zoom = true
	end

Pero en una sola funcion que ya contenga el if zoom ==... y que sirva no solo para esa booleana, si no para todas las que quiera.

Gracias.


 

 

Imagen de Chimecho

pues...

Suponiendo que quieres hacer que en N pasadas (un for de 1 a N, o un while que se repita sólo N veces con condiciones y tal), todas y cada una de tus velocidades serían:

velocidad = (posicion_final - posicion_inicial)/N

Saludos!



PSP FAT [5.00 M33-6] [6.60 ME] [Hard Moded] / Nintendo Wii [4.1U] [cIOS Hermes] [D2X cIOS] / iPhone 3G [4.2.1] [BB 05.13.04] [redsn0w] / iPod Touch 4 [6.1] [evasi0n]

07/05/10: Tuve el placer de llamarle con todo derecho "N00B" a molotovi xDDD

Recuerda: Sé el intérprete -_-

Me sigue fallando.

Mira el code:

thunder = {img = image.load("Recursos/img.png"),x=400,y=200,a=255}
fondo = image.create(480,272,color.new(89,189,23))
 
function move(tab,fx,fy,n)
	vel1 = (fx - tab.x)/n
	vel2 = (fy - tab.y)/n
	return vel1,vel2
	while true do
		tab.x = tab.x + vel1
		tab.y = tab.y + vel2
			if tab.x >= fx then tab.x = fx end
			if tab.y >= fy then tab.y = fy end
	end
end
 
thunder.img:center()
 
while true do
controls.read()
fondo:blit(0,0)
thunder.img:blit(thunder.x,thunder.y)
	if controls.press("cross") then
		fondo:blit(0,0)
		move(thunder,40,50,5)
	end
	if controls.select() and controls.start() then
		dove()
	end
	screen.flip()
end


 

 

Imagen de Chimecho

ejem...

return vel1, vel2

Retornas esos valores, y todo lo que esté luego del return (eso incluye al while), simplemente, no se hace

Opciones de visualización de comentarios

Seleccione la forma que prefiera para mostrar los comentarios y haga clic en «Guardar las opciones» para activar los cambios.