How to move objects in the right direction?

My required directions:

enter image description here I saw an example of droid activity, as well as an example of rockpaperscissors on how to move images in different directions, either with your hand or in a collision with walls.

Issue1:

Now I want to move four different images in four directions, as shown above. And when they touch the wall, they should disappear and start again from the starting point one after another and again follow in the same direction.

Issue2:

When any of them is affected by the move, it should disappear and should not continue the cycle for this image, or it should move on to another action. Please help me with these two problems. Thanks at Advance.

+4
source share
1 answer

You can use these functions in API 11

((TextView)findViewById(R.id.textView)).setTranslationX(200); ((TextView)findViewById(R.id.textView)).setTranslationY(300); 

Update Try this code code code.

  final TextView tv = (TextView)findViewById(R.id.textView); new Timer().schedule(new TimerTask() { @Override public void run() { MainActivity.this.runOnUiThread(new Runnable() { public void run() { tv.setTranslationX(tv.getTranslationX()+10); tv.setTranslationY(tv.getTranslationY()+10); tv.invalidate(); } }); } }, 1000 , 1000); tv.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast.makeText(getApplicationContext(), "Clicked!", Toast.LENGTH_SHORT).show(); } }); 

Refresh

To realize what you showed in the picture. Here is a short description to implement this

  • Create path arrays (a 2D point array) for each view on which

    views will travel

  • Create timers for each view with a repetition interval of 100 ms or less, as needed.

  • In these timers, get a point from this array of paths and pass it to your view.

  • The cycle along this path forever means a circular way.

  • set a onClck() Listener for this view.

  • In this listener, cancel () the appropriate timer for this view and destroy that view or set the visibility to GONE.

In order for all this to be implemented, you can easily complete this task.

+3
source

All Articles