logo
down
shadow

Why does my move() method not keep the ball in bounds?


Why does my move() method not keep the ball in bounds?

By : user2954134
Date : November 22 2020, 01:01 AM
To fix this issue Your move is wrong. The logic of it is false. You want the ball to bounce so make its movement reverse when it hits a wall. What you've done is : if it is outside get it inside and when inside try to get it outside! Change to:
code :
   public void move(){
        if (x < 0) { // left bound
            dx = 1;  // now move right
        }
        if (y < 0){  // upper bound
            dy = 1;  // now move down
        }
        if (x > 600){// right bound
            dx = -1; // now move left
        }
        if (y >500){ // lower bound
            dy = -1; // now move up
        }
        x += dx;
        y += dy;
    }
   public void move(){
        if (x < 0) {   // left bound
            dx = -dx;  // now move right, same speed
            x=-x;      // bounce inside
        }
        if (y < 0){    // upper bound
            dy = -dy;  // now move down, same speed
            y=-y;      // bounce inside
        }
        if (x > 600){      // right bound
            dx = -dy;      // now move left, same speed
            x=600-(x-600); // bounce inside
        }
        if (y >500){       // lower bound
            dy = -dy;      // now move up, same speed
            y=500-(y-500); // bounce inside
        }
        x += dx;
        y += dy;
    }


Share : facebook icon twitter icon
Making a method so as to be able to move the ball in PapiJump sideways by touching the sides of the screen

Making a method so as to be able to move the ball in PapiJump sideways by touching the sides of the screen


By : Campeador
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Nothing obviously wrong there that I can see (assuming you have defined all your constants, etc.)
Having been bitten by it a few times, the first thing I check now with odd crashes is if there are any broken IBOutlet or IBAction links on the viewController owner (indicated by those orange alert triangles).
Program that should move a ball, but method run is not executed

Program that should move a ball, but method run is not executed


By : Greg Zeck
Date : March 29 2020, 07:55 AM
I wish this help you , You need to pass an instance of Runnable to Thread constructor:
code :
Thread th = new Thread();
Thread th = new Thread(this);
How to add a ball over the line and move the ball with each click in HTML5?

How to add a ball over the line and move the ball with each click in HTML5?


By : hamza nasab
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I'm trying to create this ball moving. So each click it's supposed to add a ball to the end of the line from the right and as the animation still runs the ball will move to the left until it disappears. So if I click the button 5 times I should have 5 balls moving at the same time but the first will go first and follow by the rest of the balls. And the distance should depend on when the button is clicked. , You can make a list of balls
code :
var balls = [];
jQuery('#addBall').click(function() {
    balls.push(new Ball());
});
function Ball() {
    this.pos = 400;
    this.render = function() {
        this.pos -= 1;      

        context.beginPath();
        context.arc(this.pos, 10, 5, 0, 2 * Math.PI, false);
        context.fillStyle = 'green';
        context.fill();
        context.lineWidth = 5;
        context.strokeStyle = '#003300';
        context.stroke();
    };
}
function animloop() {
    requestAnimFrame(animloop);

    clearScreen();
    drawALine();
    for(var i = 0; i < balls.length; i++) {
        balls[i].render();
    }
}
Swift Pong(No SpriteKit): How to calculate ball angles to move ball

Swift Pong(No SpriteKit): How to calculate ball angles to move ball


By : Maris Reinfelds
Date : March 29 2020, 07:55 AM
I hope this helps . Simply put, you need to reverse the ball velocity 'x' if reached x-boundary and 'y' if reached y-boundary.
Considering no friction or acceleration any and no other factors to effect the velocity. Lets say the ball is traveling 60 degrees towards bottom right and hits right boundary. It needs to travel below on same 'y' velocity while returning towards left with same 'x' velocity. And as it hits bottom boundary, it will still move towards left, while returning towards top with same 'y' velocity.
code :
var posX = 0
var posY = 0
var velX = 5
var velY = 8

func moveBall(){
    posX += velX
    posY += velY
    if collideOnXBoundary {
        velX = -velX
    }
    if collideOnYBoundary {
        velY = -velY
    }
}
iPhone:Move a ball according to shake and bounce the ball on edge

iPhone:Move a ball according to shake and bounce the ball on edge


By : user3903067
Date : March 29 2020, 07:55 AM
I wish this help you Your drawing code won't make much of a difference, I will assume you know how to draw what it is you want to draw. What is important here is setting up physics. If you have a physics engine running (like Chipmunk or others) then the effects of the shake to move the ball, which I'll get to in a second, may cause the ball to move in a different direction, if that's how you've written your physics. Keep this in mind. I'll assume for the moment that gravity is off.
The idea you want to do is first to figure out whether or not you're going to target iOS prior to version 3.2, because our gesture APIs are different between the two (one way works in 3.2 and later as well, but you really want to use gesture recognizers if you're not worried about supporting 3.0 or 3.1).
Related Posts Related Posts :
  • How to write generic Java API without method Overloading
  • Java Serialization / Deserialization of an ArrayList works only on first program execution
  • Conway's Game of Life's rules dont apply properly
  • call a java method when Click on a html button without using javascript
  • Why does SSLSocketFactory.createSocket returns a Socket instead of SSLSocket?
  • How to schedule a task in Tomcat
  • compare two pdf files (approach) using java
  • What is the use of allowCoreThreadTimeout( ) in ThreadPoolExecutor?
  • Describe the Strategy Design Pattern in Java?
  • MongoDB too many open connections
  • Issue with generate JAXB classes with value constructors
  • Moving from one frame to another in java swing
  • Get a thread by Id
  • how to open front camera and back camera at same time?
  • Messed up with Java Declaration
  • Extracting chart in EXcel as image using java
  • How to get latitude and longitude in Android phone?
  • Do GC pauses and kill -STOP produce the same behavior?
  • Android HTML.ImageGetter Images resized
  • The way to instantiate map<String, List<String>> in Java
  • Java Making objects move while buttons held
  • Androidx Navigation View - `setNavigationItemSelectedListener` Doesn't Work
  • after compiling code JFrame does not appear
  • Netbeans project, JFrames ran from the main JFrame close all JFrames in project
  • Square Retrofit Client: How to enable/disable followRedirects? How to intercept redirect URL?
  • Java Circular Reference - Can’t Compile
  • Mouse click on specific time JAVA
  • android 4 onCreateDialog return type incompatible when overriding
  • Java Implementation of Oracle's DBMS_UTILITY.GET_HASH_VALUE Function
  • javac cannot be run, and furthermore does not seem installed
  • Function to obtain a thread given its ID
  • Java File path to Executable has spaces
  • Minimum Oracle Java VM heap memory setting?
  • Elegant way to create one of a large number of classes
  • Java fx binding styles
  • Summing weights based on string in large file
  • Android ListView setOnItemClickListener not working
  • How is the Java Bootstrap Classloader loaded?
  • Check object is blank
  • Add image between text in JEditorPane
  • Java POI Excel creating new column and new rows
  • NullPointerException when managing bean with Spring+JSF(Primefaces)
  • Content autocomplete in spring tool suite 4
  • Super Noob Help ~ MouseEvent/Frame
  • Making one project with dependencies stand-alone in Eclipse (Java)
  • Jsoup- getting certain attributes from website
  • MongoDB, how to make a link between collections with JAVA code
  • Overriding an abstract method means class abstract class or not in java?
  • Bukkit teleport - nullPointerException
  • How to check if a Float variable is negative in java
  • Servlet: Cannot forward after response has been committed
  • sql query to select a specific cell in excel
  • How to make new picture when mouse dragged in java
  • Use Constants interface in GWT Project
  • Setting size of a JPanel in GroupLayout
  • Construct a map from two equal size arrays
  • Implementing Read-Write Locks with Double-Checked Locking
  • Disable NO_BUTTON from JOptionPane Java if a condition is true
  • UDP multiple socket
  • Android Threading: This Handler class should be static or leaks might occur
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org