function - Android: Change speed of a ball using SeekBar -



function - Android: Change speed of a ball using SeekBar -

i have written app shows bouncing ball on screen. want add together seekbar increases velocity of ball when alter value. made functions in ball class , set x , y velocities.

package perseus.gfx.test; import everything; public class gfxactivity extends activity implements onseekbarchangelistener { viewgroup.layoutparams vg = new viewgroup.layoutparams(-1, -1); double velx, vely; double x, y; double finx, finy; seekbar velo; textview tv; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); ball ball = new ball(this); setcontentview(r.layout.main); addcontentview(ball, vg); tv = (textview)findviewbyid(r.id.test); velo = (seekbar)findviewbyid(r.id.vel); velo.setonseekbarchangelistener(this); x = ball.getspeedx(); y = ball.getspeedy(); ball.setspeedx(finx); ball.setspeedy(finy); } @override public void onprogresschanged(seekbar arg0, int arg1, boolean arg2) { finx = x + arg1; finy = y +arg1; } @override public void onstarttrackingtouch(seekbar arg0) { //nothing } @override public void onstoptrackingtouch(seekbar arg0) { //nothing } }

the problem is, (i think), local values of fin1 , fin2 affected, , ball doesn't move @ all. how pass values of fin1 , fin2 oncreate()?

you don't need pass them oncreate (not possible, anyhow), should need set ball's speed 1 time again @ end of onprogresschanged()

@override public void onprogresschanged(seekbar arg0, int arg1, boolean arg2) { finx = x + arg1; finy = y +arg1; ball.setspeedx(finx); ball.setspeedy(finy); }

android function android-widget seekbar

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -