0
I’m using the following code inside a Timer:
void dt_Tick(object sender, EventArgs e)
{
double x, y;
int cont = 0;
x = tt.X;
y = tt.Y;
while(cont < 5)
{
tt.X += cont;
tt.Y += cont;
cont++;
}
while(cont > 0)
{
tt.X -= cont;
tt.Y -= cont;
cont--;
}
tt.X = x;
tt.Y = y;
}
It would be for a button, change the position of its X and Y to give an effect as if it were shaking, how do I do that? With this code he stands still, taking out the last two lines, he just keeps going up on the screen.
I tried so to make a rather abrupt effect:
double x, y;
int cont = 0;
x = tt.X; //armazana varaivel X para manipulação
y = tt.Y; //backup da variavel Y
while (cont < 20)
{
if(dt.Interval.TotalSeconds % 2 == 0)
{
tt.X = (20 - cont);
}
else
{
tt.X = (20 - cont);
}
cont++;
}
It didn’t work very well, with Sleep gave the application a slow look, and the effect didn’t work, so I made some changes, the first one he went crazy, going left, the other one he just took a little step and stopped.. I updated the post
– Leonardo
So as I said I did not do in windows phone the project so Sleep is very expensive for mobile. but the idea is as follows. Move the button 20 pixels to the right (pause +/- 20 milliseconds) turn the button to the center (20 pixels to left) move the button 20 pixels to the left (pause +/- 20 milliseconds) and turn the button to the center (20 pixels to the right). After that decrease 1 and do it all again.
– Erick Gallani
If you can not resolve by night I post a reply at night for windows phone.
– Erick Gallani
@Leonardovilarinho take a look at this, it doesn’t help you directly but I did because I see that everyone uses the resource the wrong way: http://answall.com/q/86014/101
– Maniero