How to move circle with arrow keys? - java

I want to move a white circle on a black background using left and right arrow keys. The KeyListener is working (using System.out.print) but the circle does not move when keys are pressed. I think it has to do with the x & y positions (xPos, yPos).
private static final int SPEED = 50, BALL_SIZE = 50;
private int dx;
private int xPos, yPos;
public Background() {
addKeyListener(this);
setBackground(Color.BLACK);
// the starting point of ball
xPos = 100;
yPos = 700;
dx = SPEED;
}
#Override
public void actionPerformed(ActionEvent e) {
// screen size
int width = getWidth();
xPos += dx;
// boundaries
if (xPos < 100) {
xPos = 100;
dx = SPEED;
}
else if (xPos > width - BALL_SIZE) {
xPos = width - BALL_SIZE;
dx = -SPEED;
}
repaint();
}
#Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_RIGHT) { // right arrow key
dx++;
}
else if (e.getKeyCode() == KeyEvent.VK_LEFT) { // left arrow key
dx--;
}
else if (e.getKeyCode() == KeyEvent.VK_SPACE) { // space bar
// shoot laser!
}
System.out.println("After");
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.WHITE);
g.fillOval(xPos, yPos, BALL_SIZE, BALL_SIZE);
}

Related

Pushing another object in java.awt.Graphics

I have managed to push the other object but not the way I want it to, what I was trying to do is to push the other object towards the direction where I am pushing to other object like when you push a box or something. But in this case, I can't quite get how to push the other object to the same direction I am pushing it.
In this case: Box 1 pushing Box 2 from the -x(left) direction so the Box 2 will go towards the +x(right) direction and same with box 1 pushing box 2 from the -y(down) direction then box 2 will go towards +y(up) direction.
Here is the code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Main2 extends JFrame implements KeyListener, ActionListener {
public static int x = 0;
public static int y = 0;
public static int x2 = 100;
public static int y2 = 100;
public Main2() {
add(new panel());
}
public static void main(String[] args) {
Main2 test = new Main2();
test.setTitle("TEST");
test.setSize(Toolkit.getDefaultToolkit().getScreenSize());
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setVisible(true);
test.addKeyListener(test);
}
public class panel extends JPanel {
public panel() {
Container c = getContentPane();
c.setBackground(Color.white);
}
public void paint(Graphics g) {
super.paint(g);
object1(g, x, y);
g.setColor(Color.RED);
object2(g, x2, y2);
Rectangle object1 = new Rectangle(x, y, 25, 25);
Rectangle object2 = new Rectangle(x2, y2, 50, 50);
object1.contains(x, y);
object2.contains(x2, y2);
if (object1.intersects(object2.getX(), object2.getX(), object2.getX(), object2.getX())) {
x2 += 50;
y2 += 0;
}
pause(1);
repaint();
}
}
public static void pause(int time) {
try
{
Thread.sleep(time);
} catch (InterruptedException e) {
}
}
public void actionPerformed(ActionEvent e) {
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == e.VK_RIGHT) {
x += 20;
repaint();
}
if (e.getKeyCode() == e.VK_LEFT) {
x -= 20;
repaint();
}
if (e.getKeyCode() == e.VK_UP) {
y -= 20;
repaint();
}
if (e.getKeyCode() == e.VK_DOWN) {
y += 20;
repaint();
}
}
public void object1(Graphics g, int x, int y) {
g.fillRect(x, y, 30, 30);
}
public void object2(Graphics g, int x, int y) {
g.fillRect(x2, y2, 50, 50);
}
}
One option would be to keep track of the direction the box is moving:
enum Direction {NONE, LEFT, RIGHT, UP, DOWN};
Direction dir = Direction.NONE;
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == e.VK_RIGHT) {
x += 20;
dir = Direction.RIGHT;
repaint();
}
if (e.getKeyCode() == e.VK_LEFT) {
x -= 20;
dir = Direction.LEFT;
repaint();
}
if (e.getKeyCode() == e.VK_UP) {
y -= 20;
dir = Direction.UP;
repaint();
}
if (e.getKeyCode() == e.VK_DOWN) {
y += 20;
dir = Direction.DOWN;
repaint();
}
}
Then, when you intersect with the other rectangle, move accordingly:
if (object1.intersects(object2)) {
if (dir == Direction.RIGHT) x2 += 50;
else if (dir == Direction.LEFT) x2 -= 50;
else if (dir == Direction.DOWN) y2 += 50;
else if (dir == Direction.UP) y2 -= 50;
}

Putting a border for moving square

So basically im just playing around with movement systems for different purposes and having trouble making square stop right at the edge. Square moves off the side of screen by around 50% of the square it self and i cannot figure out why it is like that.
package SnakeMovement;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
#SuppressWarnings("serial")
public class SnakeMovement extends Canvas implements ActionListener, KeyListener {
Timer timer = new Timer(5, this);
int width, height;
int xSize = 50, ySize = 50;
int yPos = 0, xPos = 0, yVel = 0, xVel = 0;
public SnakeMovement(int w, int h) {
timer.start();
width = w;
height = h;
addKeyListener(this);
setFocusTraversalKeysEnabled(false);
setFocusable(true);
}
public void paint(Graphics g) {
super.paint(g);
g.fillRect(xPos, yPos, xSize, ySize);
}
public void actionPerformed(ActionEvent e) {
xPos += xVel;
yPos += yVel;
if (xPos >= width - xSize) {
xPos = width - xSize;
xVel = 0;
}
repaint();
}
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_W) {
yVel = -10;
xVel = 0;
}
if (key == KeyEvent.VK_S) {
yVel = 10;
xVel = 0;
}
if (key == KeyEvent.VK_A) {
xVel = -10;
yVel = 0;
}
if (key == KeyEvent.VK_D) {
xVel = 10;
yVel = 0;
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
}
I just want so square stops at each side of screen perfectly on the edge.
Try:
private static final int BORDER_SIZE = 1;
private static final Color RECT_COLOR = Color.BLUE, BORDER_COLOR = Color.RED;
#Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(BORDER_COLOR);
g.fillRect(xPos, yPos, xSize, ySize);
g.setColor(RECT_COLOR);
g.fillRect(xPos+BORDER_SIZE, yPos+BORDER_SIZE, xSize-2*BORDER_SIZE, ySize-2*BORDER_SIZE);
}
The idea is to paint a full size rectangular using the border color.
Then painting a smaller one (smaller by 2*BORDER_SIZE) using the rectangular color.
The following is mre of the above:
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.Timer;
public class SnakeMovement extends Canvas implements ActionListener, KeyListener {
private static final int BORDER_SIZE = 1, DELAY = 100;
private static final Color RECT_COLOR = Color.BLUE, BORDER_COLOR = Color.RED;
private final int xSize = 50, ySize = 50;
private int yPos = 0, xPos = 0, yVel = 5, xVel = 5;
private final Timer timer = new Timer(DELAY, this);
public SnakeMovement(int width, int height) {
timer.start();
addKeyListener(this);
setFocusTraversalKeysEnabled(false);
setFocusable(true);
setPreferredSize(new Dimension(width, height));
}
#Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(BORDER_COLOR);
g.fillRect(xPos, yPos, xSize, ySize);
g.setColor(RECT_COLOR);
g.fillRect(xPos+BORDER_SIZE, yPos+BORDER_SIZE, xSize-2*BORDER_SIZE, ySize-2*BORDER_SIZE);
}
#Override
public void actionPerformed(ActionEvent e) {
xPos += xVel;
yPos += yVel;
checkLimits();
repaint();
}
//when canvas edge is reached emerge from the opposite edge
void checkLimits(){
//check x and y limits
if (xPos >= getWidth()) {
xPos = -xSize;
}
if (xPos < -xSize ) {
xPos = getWidth();
}
if (yPos >= getHeight() ) {
yPos = -ySize;
}
if (yPos < -ySize ) {
yPos = getHeight();
}
}
//two other behaviors when hitting a limit. uncomment the desired behavior
/*
//when canvas edge is reached change direction
void checkLimits(){
//check x and y limits
if ( xPos >= getWidth() - xSize || xPos <= 0) {
xVel = - xVel;
}
if ( yPos >= getHeight() - ySize || yPos <= 0) {
yVel = - yVel;
}
}
*/
/*
//when canvas edge is reached stop movement
void checkLimits(){
//check x and y limits
if ( xPos >= getWidth() - xSize || xPos <= 0 || yPos >= getHeight() - ySize || yPos <= 0) {
timer.stop();
}
}
*/
#Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_W) {
yVel = -10;
xVel = 0;
}
if (key == KeyEvent.VK_S) {
yVel = 10;
xVel = 0;
}
if (key == KeyEvent.VK_A) {
xVel = -10;
yVel = 0;
}
if (key == KeyEvent.VK_D) {
xVel = 10;
yVel = 0;
}
}
#Override
public void keyReleased(KeyEvent e) {
}
#Override
public void keyTyped(KeyEvent e) {
}
public static void main(String[] args0) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new SnakeMovement(500, 500));
frame.pack();
frame.setVisible(true);
}
}

Collision effects in Java

Is it possible to add collision effects to an image in Java, drawn using the drawImage() method ? If so, how could I do it?
Example:
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
public class Racquet {
private static final int Y = 330;
private static final int WIDTH = 60;
private static final int HEIGHT = 10;
int x = 0;
int xa = 0;
private Game game;
public Racquet(Game game) {
this.game = game;
}
public void move() {
if (x + xa > 0 && x + xa < game.getWidth() - WIDTH)
x = x + xa;
}
public void paint(Graphics2D g) {
g.fillRect(x, Y, WIDTH, HEIGHT);
}
public void keyReleased(KeyEvent e) {
xa = 0;
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_LEFT)
xa = -1;
if (e.getKeyCode() == KeyEvent.VK_RIGHT)
xa = 1;
}
public Rectangle getBounds() {
return new Rectangle(x, Y, WIDTH, HEIGHT);
}
public int getTopY() {
return Y;
}
}
Ball class:
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class Ball {
private static final int DIAMETER = 30;
int x = 0;
int y = 0;
int xa = 1;
int ya = 1;
private Game game;
public Ball(Game game) {
this.game= game;
}
void move() {
if (x + xa < 0)
xa = 1;
if (x + xa > game.getWidth() - DIAMETER)
xa = -1;
if (y + ya < 0)
ya = 1;
if (y + ya > game.getHeight() - DIAMETER)
game.gameOver();
if (collision()){
ya = -1;
y = game.racquet.getTopY() - DIAMETER;
}
x = x + xa;
y = y + ya;
}
private boolean collision() {
return game.racquet.getBounds().intersects(getBounds());
}
public void paint(Graphics2D g) {
g.fillOval(x, y, DIAMETER, DIAMETER);
}
public Rectangle getBounds() {
return new Rectangle(x, y, DIAMETER, DIAMETER);
}
}
The above code detects the collision between the racquet and the ball, now, if my racquet/racket was an image, How wuold I be able to detect the collision of it with the ball? Also, are there easier ways for collision detection?(just asking)
class MyImage extends BufferedImage {
int x, y, xa, ya;
public Rectangle getBounds() {
return new Rectangle(x, y, getWidth(), getHeight());
}
// all other methods in raquet remain the same except you remove paint()
private Game game;
public MyImage(Game game) {
this.game = game;
}
public void move() {
if (x + xa > 0 && x + xa < game.getWidth() - WIDTH)
x = x + xa;
}
public void keyReleased(KeyEvent e) {
xa = 0;
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_LEFT)
xa = -1;
if (e.getKeyCode() == KeyEvent.VK_RIGHT)
xa = 1;
}
public int getY() {
return y;
}
}
To start an image you read it like this
MyImage myImage=null;
try {
myImage=ImageIO.read(new File(...));
}
catch (Exception ex) { ex.printStackTrace(); }
How wuold I be able to detect the collision of it with the ball?
I see that you already have a getBounds() methods which returns a Rectangle object. You can use this to check for collision.
You can do it like:
if(racquet.getBounds().intersects(ball.getBounds()))
//collision happens
If the ball must be within the racquet, then:
if(racquet.getBounds().contains(ball.getBounds()))
//collision happens
However, if the height of your racquet object includes then length of the racquet handle, you may implement a getHitBox() method for the racquet something like this:
public Rectangle getHitBox(){
return new Rectangle(x, Y, WIDTH, HEIGHT-handleHeight);
}
Is it possible to add collision effects to an image in Java, drawn using the drawImage() method ? If so, how could I do it?
Not sure how your drawImage() was implemented, so I can't comment on that. However, it is definitely possible to add some "collision effects" with custom painting. Whenever a collision is detected, play the animation at specific location (which will be the location where collision occurs).
You may construct a method like:
playAnimation(int locX, int locY, Animation anima, int duration)
In this case Animation class can just play the sprites from a sprite sheet.
Also, are there easier ways for collision detection?(just asking)
You will probably only have 1 ball and at most 4 racquets in your game. In this case, you only need to check whether the ball hits any of the racquets:
for(int x=0; x<allRacquets.size(); x++)
if(allRacquets.get(x).collidesWith(ball))
collidedRacquet = allRacquets.get(x);
CollidesWith() method can be implemented from the collision detection approach mentioned above:
//implement within Racquet class
public boolean collidesWith(Ball ball){
return (this.getBounds().intersects(ball.getBounds()));
}

How Do I Make my 2D Pong Racquets Move Up and Down, Rather than Side to Side?

I saw a lot of results on how do move a sprite in Java, but I can't find any that suite my code. I'm following a tutorial on how to make a Pong style game.
You can find the tutorial here. (That's the part I encountered the problem).
Here's my code for the Racquet class:
package com.tennis;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
public class Racquet {
private static final int Y = 330;
private static final int WIDTH = 60;
private static final int HEIGHT = 10;
int x = 0;
int xa = 0;
private Game game;
public Racquet(Game game) {
this.game = game;
}
public void move() {
if(x + xa > 0 && x + xa < game.getHeight()-60)
x = x + xa;
}
public void paint(Graphics2D g) {
g.fillRect(x, 50, 10, 70);
}
public void keyReleased(KeyEvent e) {
xa = 0;
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_UP)
xa = -1;
if(e.getKeyCode() == KeyEvent.VK_DOWN)
xa = 1;
}
public Rectangle getBounds() {
return new Rectangle(x, Y, WIDTH, HEIGHT);
}
public int getTopY() {
return Y;
}
}
Now the part I'm looking at that I need help changing is this:
public void keyReleased(KeyEvent e) {
xa = 0;
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_UP)
xa = -1;
if(e.getKeyCode() == KeyEvent.VK_DOWN)
xa = 1;
}
public Rectangle getBounds() {
return new Rectangle(x, Y, WIDTH, HEIGHT);
}
Alrighty, so the actual problem I have is that I need the Racquet to move up and down along the Y axis, at the current moment it's moving along the X axis.
In your move() function replace x = x + xa to:
y = y + xa;
x variable supposed to be y, and pass to the 2nd param for fillRect
public void paint(Graphics2D g) {
g.fillRect(50, x, 10, 70);
}
public abstract void fillRect(int x,
int y,
int width,
int height)
x - the x coordinate of the rectangle to be filled.
y - the y coordinate of the rectangle to be filled.
width - the width of the rectangle to be filled.
height - the height of the rectangle to be filled.
I was overcomplicating things by trying to make the ping pong racquet move on the Y axis instead of the X axis, so I switched it. Problem solved-ish. Now I can finish the game and continue onto making funner Java games.
So I messed around with these integers,
public void paint(Graphics2D g) {
g.fillRect(x, 250, 70, 10);
}
Then I made the keys as so:
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_LEFT)
xa = -1;
if(e.getKeyCode() == KeyEvent.VK_RIGHT)
xa = 1;
}

Why does my player continue to move (very slowly) after releasing the arrow keys?

I'm working on my first 2D Java game using Swing, and I've run into an odd bug.
Here's the relevant code, first of all:
GamePanel.java
public class GamePanel extends JPanel implements KeyListener {
public GamePanel() {
setPreferredSize(new Dimension(STAGE_WIDTH, STAGE_HEIGHT));
Thread runner = new Thread(new Runnable() {
#Override
public void run() {
begin();
long lastUpdate = System.currentTimeMillis();
while (true) {
long elapsed = System.currentTimeMillis() - lastUpdate;
repaint();
if (elapsed < 16) {
try {
Thread.sleep(20 - elapsed);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
update((System.currentTimeMillis() - lastUpdate) / 1000.0);
lastUpdate = System.currentTimeMillis();
}
}
});
runner.start();
}
//variables
int bulletVelocity = 10;
final int STAGE_HEIGHT = 600;
final int STAGE_WIDTH = 800;
int playerWidth = 50;
int playerHeight = 50;
//lists
List<Bullet> bulletList = new ArrayList<>();
List<Enemy> enemyList = new ArrayList<>();
//objects
Player player = new Player((STAGE_WIDTH - playerWidth) / 2, (STAGE_HEIGHT - playerHeight) / 2, 0, 0, playerWidth, playerHeight);
public void begin() {
}
public void update(double delta) {
player.update(delta);
//System.out.println(delta);
for (Bullet bullet : bulletList) {
bullet.update();
}
for (Enemy enemy : enemyList) {
enemy.update(player.getXPos(), player.getYPos());
}
}
#Override
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.RED);
g.fillRect((int) player.getXPos(), (int) player.getYPos(), player.getWidth(), player.getHeight());
g.setColor(Color.BLUE);
for (Bullet bullet : bulletList) {
g.fillRect((int) bullet.getXPos(), (int) bullet.getYPos(), 10, 10);
}
g.setColor(Color.GREEN);
for (Enemy enemy : enemyList) {
g.fillOval((int) enemy.getXPos(), (int) enemy.getYPos(), enemy.getWidth(), enemy.getHeight());
}
}
#Override
public void keyTyped(KeyEvent e) {
}
private Set<Integer> keysDown = new HashSet<Integer>();
#Override
public void keyPressed(KeyEvent e) {
if (keysDown.contains(e.getKeyCode())) {
return;
}
keysDown.add(e.getKeyCode());
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
player.addAccelX(-1);
} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
player.addAccelX(1);
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
player.addAccelY(-1);
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
player.addAccelY(1);
} else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
Bullet bullet = new Bullet(player.getXPos() + (player.getWidth() / 2), player.getYPos(), bulletVelocity - (player.getYVel() / 4));
bulletList.add(bullet);
} else if (e.getKeyCode() == KeyEvent.VK_E) {
Enemy enemy = new Enemy(100, 100, Math.random() * 3 + .5, 10, 10);
enemyList.add(enemy);
} else if (e.getKeyCode() == KeyEvent.VK_A) {
System.out.println(toDegrees(atan2(player.getYPos() - 0, player.getXPos() - 0)));
}
}
#Override
public void keyReleased(KeyEvent e) {
keysDown.remove(e.getKeyCode());
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
player.addAccelX(1);
} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
player.addAccelX(-1);
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
player.addAccelY(1);
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
player.addAccelY(-1);
}
}
}
Player.java
public class Player {
private final double MAX_VELOCITY = 500;
private final double ACCELERATION = 3000.0;
//friction is % ? Add that later
private final double FRICTION = 400.0;
private double mass = 10.0;
private double xPos = 400;
private double yPos = 200;
private double xVel = 0.0;
private double yVel = 0.0;
private int width = 100;
private int height = 100;
private int xDir = 0;
private int yDir = 0;
private boolean moving = false;
private double accelX = 0.0;
private double accelY = 0.0;
public Player() {
}
public Player(double xPos, double yPos, double xVel, double yVel, int width, int height) {
this.xPos = xPos;
this.yPos = yPos;
this.xVel = xVel;
this.yVel = yVel;
this.width = width;
this.height = height;
}
public void update(double delta) {
this.xVel += accelX * delta;
this.yVel += accelY * delta;
if(abs(xVel) > MAX_VELOCITY){xVel = MAX_VELOCITY * xDir;}
if(abs(yVel) > MAX_VELOCITY){yVel = MAX_VELOCITY * yDir;}
if(xVel > 0) xVel += -FRICTION / mass;
if(xVel < 0) xVel += FRICTION / mass;
//debugging
//System.out.println(yVel);
if(yVel > 0) yVel += -FRICTION / mass;
if(yVel < 0) yVel += FRICTION / mass;
//System.out.println(yVel);
//if(!moving){xVel = 0; yVel = 0;}
this.xPos += this.xVel * delta;
this.yPos += this.yVel * delta;
}
public void setMoving(boolean moving){
this.moving = moving;
}
public void move(double delta) {
/*
* Acceleration = Force / Mass
* Velocity += Acceleration * ElapsedTime (delta)
* Position += Velocity * ElapsedTime (delta)
*/
}
public double getAccel(){
return ACCELERATION;
}
public void addAccelX(int dir) {
this.accelX += ACCELERATION * dir;
//this.xDir = dir;
}
public void addAccelY(int dir) {
this.accelY += ACCELERATION * dir;
//this.yDir = dir;
}
public double getXPos() {
return this.xPos;
}
public double getYPos() {
return this.yPos;
}
public double getXVel() {
return this.xVel;
}
public double getYVel() {
return this.yVel;
}
public int getHeight() {
return this.height;
}
public int getWidth() {
return this.width;
}
public void addXPos(int delta) {
this.xPos += delta;
}
public void addYPos(int delta) {
this.yPos += delta;
}
public void addXVel(int delta) {
this.xVel += delta;
}
public void addYVel(int delta) {
this.yVel += delta;
}
}
(Please excuse the sloppy code.)
The little red square player moves fine, but when I release the arrow keys, the player moves (either down or to the right) with a velocity of 20 (arbitrary units at this point), which comes out to a few pixels/sec.
I think that it has something to do with the friction, but I'm not sure.
You never reset accelX and accelY and so the acceleration is continuously applied across frames. Your player should actually be accelerating, but I think that friction may be interacting in some way to create slow movement.

Categories

Resources