Título: Emular desplazamiento
Publicado por: diego_lp en 18 Febrero 2010, 21:27 pm
Hola de nuevo, estoy volviendome loco con mi programa y necesito ayuda. Les cuento mas o menos la idea a ver si a alguien se le ocurre algo: Tengo un modulo en visual basic .net, que tiene un bucle principal, del cual no se la velocidad exacta pero es muy rapido :rolleyes: Por otro lado tengo un timer con un intervalo de 500 milisegundos. Cada tick del timer mi programa se conecta a una base de datos y obtiene las coordenadas X Y de determinados objetos y guarda los objetos en un array. El bucle principal simplemente actualiza las coordenadas del objeto con las nuevas obtenidas cada tick del timer. Bueno el problemas es éste: Si tomamos por ejemplo un objeto, que al hacer un tick el timer su propiedad X vale 10 (es decir objeto.X=10) y al volver a hacer tick la propiedad X del objeto vale 50, el bucle principal me actualiza directamente de 10 a 50. Lo que yo necesito es que cada ciclo del bucle principal se actualize en 1, es decir, que el bucle principal por cada ciclo le agregue 1 al valor inicial de X hasta llegar a 50. Necesito alguna idea de cómo hacer ésto, al menos en pseudocódigo, no logro razonarlo de la forma correcta para que me funcione. Espero que se haya entendido ;D Muchas gracias.
Título: Re: Emular desplazamiento
Publicado por: elmaro en 18 Febrero 2010, 22:06 pm
Ponte el código que tienes y lo miro
Título: Re: Emular desplazamiento
Publicado por: MANULOMM en 18 Febrero 2010, 22:11 pm
Ponte el código que tienes y lo miro
Lo mismo. Atentamente, Juan Manuel Lombana Medellín - Colombia
Título: Re: Emular desplazamiento
Publicado por: diego_lp en 18 Febrero 2010, 22:52 pm
COdigo del Timer: Public MyTimer As New System.Timers.Timer(1000) '1000 es el intervalo en milisegundos 'Este es el procedimiento que ejecutara el timer Public Sub CodeToRun() 'bloque de codigo que se ejecuta cada 1 segundo Try Dim Com As New OdbcConnection("dsn=mysql_juego;uid=xxxx;pwd=xxxxxx;") Com.Open() Dim Comando As New OdbcCommand("UPDATE `datos`.`usuarios` SET `X` = '" & hero.x & "' , `Y` = '" & hero.y & "' WHERE `usuarios`.`id` = " & id_usuario, Com) Comando.CommandType = CommandType.Text Comando.ExecuteNonQuery() Com.Close() Dim DA_usuarios As New OdbcDataAdapter("Select * From usuarios where mapa = '" & dt_usu.Rows(0).Item(4).ToString & "' and estado = 'libre' and id <> '" & id_usuario & "'", conexionBD) 'por segundo parametro se puede pasar un objeto conexion como directamente le string de conexion DA_usuarios.Fill(DS_usuarios, "id") 'manda ejecutar la sentecia SQL o el PA que le indicamos al adaptador y el resultado de esa ejecucion a guarda como un objeto datatable con el nombre del 2o parametro del fill dentro del dataset que le pasasmos como 1er parametro dt_usuarios = DS_usuarios.Tables("id") usuarios_online = dt_usuarios.Rows.Count Catch ex As Exception
End Try
Try If usuarios_online <> 0 Then For i = 0 To usuarios_online - 1 hero1 = New AnimatedSprite hero1.Animations.Remove("WalkUp") hero1.Animations.Remove("WalkRight") hero1.Animations.Remove("WalkDown") hero1.Animations.Remove("WalkLeft") hero1.Animations.Add("WalkUp", New Animation(walkUp, 35)) hero1.Animations.Add("WalkRight", New Animation(walkRight, 35)) hero1.Animations.Add("WalkDown", New Animation(walkDown, 35)) hero1.Animations.Add("WalkLeft", New Animation(walkLeft, 35)) hero1.TransparentColor = Color.Magenta If x1 > dt_usuarios.Rows(i).Item(5) Then hero1.CurrentAnimation = "WalkLeft" ElseIf x1 < dt_usuarios.Rows(i).Item(5) Then hero1.CurrentAnimation = "WalkRight" ElseIf y1 > dt_usuarios.Rows(i).Item(6) Then hero1.CurrentAnimation = "WalkUp" Else hero1.CurrentAnimation = "WalkDown" End If x1 = dt_usuarios.Rows(i).Item(5) y1 = dt_usuarios.Rows(i).Item(6) hero1.Center = New Point(x1, y1) heros.Insert(i, hero1) nom_hero1 = New SdlDotNet.Sprites.TextSprite(dt_usuarios.Rows(i).Item(3), fuente, Color.White, New Point(hero1.X, hero1.Y - 15)) nom_heros.Insert(i, nom_hero1) nom_hero1 = Nothing hero1 = Nothing Next Else hero1 = Nothing End If dt_usuarios.Reset() Catch ex As Exception
End Try End Sub Codigo del bcle principal: mapa1.Render(Video.Screen) logo.Render(Video.Screen) hero.Render(Video.Screen) panel.Render(Video.Screen) texto3.Render(Video.Screen) Dim usu As New SdlDotNet.Sprites.TextSprite(usuarios_online, fuente, Color.White, New Point(20, 20)) usu.Render(Video.Screen) If usuarios_online <> 0 Then For i = 0 To usuarios_online - 1 heros(i).Render(Video.Screen) nom_heros(i).Render(Video.Screen) Next End If
Título: Re: Emular desplazamiento
Publicado por: 43H4FH44H45H4CH49H56H45H en 19 Febrero 2010, 04:38 am
Se puede hacer de este modo, actualizando la posición del pictureBox con una variable que sume o reste 1 a su valor, esta en C# solo para ubicarse. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { int i = 10; int x = 0; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { i = int.Parse(textBox1.Text); } private void timer1_Tick(object sender, EventArgs e) { if (pictureBox1.Location.X < i) { x++; Point nPos = new Point (x, 158); pictureBox1.Location = nPos; this.Text = pictureBox1.Location.X.ToString(); } else if (pictureBox1.Location.X > i) { x--; Point nPos = new Point (x, 158); pictureBox1.Location = nPos; this.Text = pictureBox1.Location.X.ToString(); } } } }
|