in Education by
How can i throw any object(Stone) continuously to a moving Horizontally object? I have used a thread which can throw stone using translate animation continuously but the memory usage is very much and my device get slows down after 3-4 min.How to resolve dis problem? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I think that you would be best of implementing your own SurfaceView. In it, you can draw animated objects (using a dedicated thread) much more feely than using view-animations. (You will of course have to rewrite parts of your code for this, but it might be for the best in the long run). If you feel you want to try the SurfaceView, I recommend looking through the Lunar Lander example from android. Example: public class ThrowView extends SurfaceView implements SurfaceHolder.Callback, OnGestureListener{ //The OnGestureListener can detect a fling motion. private class DrawingThread extends Thread{ private final float timefactor = 0.0001f; //This is used to make the animation a bit slower. Play with this value if the animation seems too be to slow or too fast. private final float damp = 0.9; //This is used to slow down the object. If it stops too fast or slow, this is the value to change. private float stoneX = 0; //The x-coordinate of our stone object. Use this when drawing. private float stoneY = 0; //The y-coordinate of our stone object. Use this when drawing. @Override public void run(){ while(running){ Canvas c = null; try{ c = surfaceHolder.lockCanvas(null); synchronized (surfaceHolder) { updatePhysics(); doDraw(c); //doDraw is not in this example, but it should essentially just draw our object at stoneX, stoneY. } }finally{ if(c!=null) surfaceHolder.unlockCanvasAndPost(c); } SystemClock.sleep(40); } private void updatePhysics(long time){ //Calculate how much time has passed since last step: time1 = System.currentTimeMillis(); dT = (time1 - time2)*timefactor; time2 = time1; //Move the stone in x depending on the time and velocity: stoneX += vX*dT; //Decrease the velocity: vX -= dT*damp: } } protected volatile float vX = 0; //This is the x-speed. To be able to throw in y too, just make another variable for that. @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { //This is our onFling, here we take the velocity of the users fling and set our variable to that. //Note that this value is based on pixels. vX = velocityX; return true; } @Override public boolean onDown(MotionEvent e) { //The onDown should return true so onFling can be activated: return true; } } This example is made according to the Lunar Lander sample for ease of use. Many methods (that were not necessary for this example) are omitted here, but can be implemented according to Lunar Lander.

Related questions

0 votes
    Animation example link: https://drive.google.com/open?id=1M5UBylFj0_8mtOEQT7jjsPN9DcCjyfPI I want to show my app ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I'm wondering how to stop an animation made with jQuery timers. I think I have tried everything, I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I inserted in PostgreSQL table an UUID created with go.uuid : import ( "github.com/satori/go.uuid" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I inserted in PostgreSQL table an UUID created with go.uuid : import ( "github.com/satori/go.uuid" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I'm a bit stuck on this. Basically I want to do something like the following SQL query in LINQ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    What's the easiest way to get the filename associated with an open HANDLE in Win32? JavaScript questions ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    What's the easiest way to get the filename associated with an open HANDLE in Win32? JavaScript questions ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I have created a client-server program with Perl using IO::Socket::INET. I access server through CGI ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    Given my animation scene1. How can I pause it using a button named “Skip” using C# code behind, and play another animation scene2 after....
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    How to insert different types of slides and images into the slides and apply animation and transition on them Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    how to create an animation by using onion skin tool in computer? Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    What is the name of Artificial Intelligence which allows machines to handle vague information with a deftness that mimics ... ) Boolean logic c) Functional logic d) Fuzzy logic...
asked Jan 15, 2023 in Education by JackTerrance
0 votes
    I made an application in react and i'm using ADAL to authenticate in Azure Active Directory, so every ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm trying to re-play a Flare animation in Flutter. Not loop the animation when it has complete. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
...