I'm creating a small application where a user can take a Box and arrange it on a Pallet. I've managed to get it working using a 50x100 Box and making it snap to a grid by rounding the mouse position to the closest 50 value.
The problem is that when I use an odd sized Box, e.g. 50x110, the boxes will overlap or have gaps, since I am forcing them to move to the closest 50 value. If I increase this value I get gaps between the boxes and if I make it too small, it becomes hard for a user to align the boxes so there is no gap between them
I was wondering if anyone had anyway to approach this problem of getting the boxes to snap/align themselves with each other regardless of the size and ratio?
Here is part of the code that generates and places the buttons onto the pallet, explanation of the missing functions at the bottom
int package_width = 60;
int package_height = 100;
int snap_size = 50; //snap everything into 5 pixel limits
int count = 0;
int pallet_width = 400;
int pallet_height = 400;
JButton package_left = new JButton("<");
package_left.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent arg0) {
Selector.selected = "<";
}
});
JPanel pallet = new JPanel();
pallet.setLayout(null);
pallet.addMouseListener(new MouseAdapter() {
#Override
public void mousePressed(MouseEvent e) {
if(Selector.selected != "" && Selector.selected != null) {
Point position = e.getPoint();
JButton pack = new JButton(Selector.selected + Selector.count);
int x_pos = -1;
int y_pos = -1;
int pack_height = -1;
int pack_width = -1;
if(Selector.selected == "<" || Selector.selected == ">") {
pack_width = package_height;
pack_height = package_width;
}else {
pack_width = package_width;
pack_height = package_height;
}
pack.setSize(pack_width, pack_height);
//snap using the height and width
x_pos = (int)((int)(position.x-pack_width/2)/(pack_width/2))*pack_width/2;
y_pos = (int)((int)(position.y-pack_height/2)/(pack_height/2))*pack_height/2;
pack.setLocation(x_pos, y_pos);
if(collision(pack.getLocation(), snap_size)) {
x_pos = -1;
y_pos = -1;
}
//If the position failed to set, its overlapping
if (x_pos != -1 && y_pos != -1) {
Selector.point_list.add(pack.getLocation());
if(Selector.selected == "<" || Selector.selected == ">") {
Selector.point_list.add(new Point(pack.getLocation().x+snap_size, pack.getLocation().y));
}else{
Selector.point_list.add(new Point(pack.getLocation().x, pack.getLocation().y+snap_size));
}
pallet.add(pack);
main_page.repaint();
Selector.selected = "";
}
}
}
}
Collision Function
public static boolean collision(Point pack, int snap_size) {
Iterator<Point> it = Selector.point_list.iterator();
Point next;
while(it.hasNext()) {
next = it.next();
if(pack.x == next.x && pack.y == next.y) {
return true;
}
if(Selector.selected == "<" || Selector.selected == ">") {
if(pack.x+snap_size == next.x && pack.y == next.y) {
return true;
}
}else {
if(pack.x == next.x && pack.y+snap_size == next.y) {
return true;
}
}
}
return false;
}
The class Selector holds 2 static variables. One is the point_list which holds a list of all the points that have a button in them already. The other is selected which is used to determine the orientation of the button based on if the first button pressed has ^,v,< or > on it.
Related
I'm trying to print out an int[] array for this assignment I'm working on. My code is as follows:
import VacuumCleanerEnvironment.Constants;
import java.util.*;
/**
* Agent Class
* Student's Assignment
*/
public class Agent {
private String action = null;
public Agent() {
}
private boolean wallCheck(Set walls, int row, int col, int i){
int[] temp = {row, col};
if(i == 1){ // up
temp[0]--;
}else if(i == 2){ //right
temp[1]++;
}else if(i == 3){ // down
temp[0]++;
}else{ // left
temp[1]--;
}
return walls.contains(temp);
}
private void addWall(Set walls, int row, int col, String dir){
int[] temp = {row,col};
if(dir == "up"){
temp[0]--;
}else if(dir == "left"){
temp[1]--;
}else if(dir == "right"){
temp[1]++;
}else if(dir == "down"){
temp[0]++;
}
walls.add(temp);
}
/**
* can return:
* "up", "right", "down", "left", "suck dirt", "stay idle"
* #return String
*/
public String action(boolean dirty, boolean bump,int row, int col){
//System.out.println(Constants.SIZE);
//System.out.println(Constants.initialDirtProb);
//System.out.println(Constants.dirtyProb);
//System.out.println(Constants.dirtSensorFailProb);
//System.out.println(Constants.bumpSensorFailProb);
// System.out.println("\nbump:" + bump);
// System.out.println("dirty:" + dirty);
// System.out.println("row:" + row);
// System.out.println("col:" + col);
//int r = Constants.randomGen.getInt(4);
Set<int[]> walls = new HashSet<int[]>();
// int[] wallRoom = new int[2];
if (dirty)
{
action="suck dirt";
}
else
{
if(bump == true){
this.addWall(walls, row, col, action);
System.out.print("Walls:" + walls);
Iterator value = walls.iterator();
while(value.hasNext()){
System.out.print("," + (int[])value.next());
}
System.out.println();
}
Random r = new Random();
int i = r.nextInt(4);
while(this.wallCheck(walls, row, col, i)){
System.out.println("wallcheck: " + this.wallCheck(walls, row, col, i));
i = r.nextInt(4);
}
if(i == 1) {
action = "up";
}
else if(i == 2) {
action = "right";
}
else if(i == 3) {
action = "down";
}
else {
action = "left";
}
}
return action;
}
}
I am actually having 2 problems:1) The method wallCheck isn't running and I'm assuming it's because the int[] values are being saved as references and not values. How can I check if my HashSet contains a specific int[] value? (used to locate the walls on a map). 2) Why are my values being cut off when I print out my HashSet "walls". They are printing out like this:
Walls:[[I#1515e375],[I#1515e375
Walls:[[I#4abd1f59],[I#4abd1f59
Walls:[[I#e4612e6],[I#e4612e6
Walls:[[I#6936b791],[I#6936b791
Thanks in advance!
-------------------------------- EDIT -------------------------------
Ok guys I figured out what the problem was. Like Dave said it Java doesn't print out array's nicely, so I had to print it out myself. Also, I was declaring the HashSet INSIDE the action method, that's why only 1 value was being stored.
I am making a little game for my university coursework and got stuck at the menu creation. Been trying to solve this for a while. Here goes the code:
Before trying to fiddle around the loop and noLoop() functions and before I moved the arrow placement from void setup to void keypressed my game has worked. Now the program freezes before running draw.
What I want is to only display the menu background before the key, in this case s for start, has been pressed. If anyone could come up with some directions it would be of a great help.
Thanks in advance.
int totalArrows = 6;
arrowclass[] theArrows = new arrowclass[totalArrows];
PImage[] imgList = new PImage[4];
PImage bg;
PImage life;
PImage menu;
int score;
int loose = 3;
void setup() {
size(400, 600);
bg = loadImage("bck.jpg");
life = loadImage("life.png");
menu = loadImage("menu.jpg");
background(menu);
// loading the arrow imgs
for (int i= 0; i<4; i++) {
println(i+".png");
imgList[i] = loadImage(i+".png");
}
noLoop();
}
void draw() {
textSize(32);
text(score,30,100);
// active area
fill(255,31,31);
rect(0,500,width,100);
//lifetrack
if (loose==3){
image(life,10,10);
image(life,45,10);
image(life,80,10);
}
if (loose==2){
image(life,10,10);
image(life,45,10);
}
if (loose==1){
image(life,10,10);
}
// calling class action, movement
for (int i = 0; i<totalArrows; i++) {
theArrows[i].run();
if (theArrows[i].y>475 && theArrows[i].y<600) {
theArrows[i].inactive = true;
}
if(theArrows[i].did == false && theArrows[i].y>598) {
theArrows[i].lost = true;
}
if(theArrows[i].lost && theArrows[i].did == false && theArrows[i].wrongclick == false){
loose--;
theArrows[i].lost = false;
}
}
if (loose == 0){
textSize(32);
text("gameover",width/2,height/2);
for(int i=0; i<totalArrows;i++){
}
}
}
void keyPressed() {
if (key == 'p'){
// placing tha arrows. (i*105 = positioning) THIS PART IS AN ISSUE FOR SURE. SEE ARROW CLASS
for (int i= 0; i<totalArrows; i++) {
theArrows[i] = new arrowclass(-i*105);
}
loop();
}
}
void keyReleased() {
for (int i= 0; i<totalArrows; i++) {
if (theArrows[i].inactive && theArrows[i].did == false) {
if (keyCode == UP && theArrows[i].id == 3){
score++;
theArrows[i].did = true;
}
if (keyCode != UP && theArrows[i].id == 3){
loose--;
theArrows[i].wrongclick = true;
}
if (keyCode == DOWN && theArrows[i].id == 0){
score++;
theArrows[i].did = true;
}
if (keyCode != DOWN && theArrows[i].id == 0){
loose--;
theArrows[i].wrongclick = true;
}
if (keyCode == RIGHT && theArrows[i].id == 2){
score++;
theArrows[i].did = true;
}
if (keyCode != RIGHT && theArrows[i].id == 2){
loose--;
theArrows[i].wrongclick = true;
}
if (keyCode == LEFT && theArrows[i].id == 1){
score++;
theArrows[i].did = true;
}
if (keyCode != LEFT && theArrows[i].id == 1){
loose--;
theArrows[i].wrongclick = true;
}
}
}
}
And the arrow class:
class arrowclass{
int y;
int id;
boolean did;
boolean inactive;
boolean lost;
boolean wrongclick;
// proprieties of the class
arrowclass(int initY){
y = initY;
id = int(random(4));
did = false;
inactive = false;
lost = false;
wrongclick = false;
}
//actions
void run(){
image(imgList[id],width/2,y);
// score goes up, speed goes up
y += 2+score;
// reset arrow to default
if (y>600) {
y = -50;
id = int(random(4));
inactive = false;
did = false;
lost = false;
wrongclick = false;
}
}
}
Currently I have a game that I am building in Netbeans, and have been able to create a board, place the pieces and allow them to be moved anywhere using mouseveent's
But now I have ran into a problem when trying to code the pieces on the board to only do allowed actions.
The problem I am having is that every piece is still allowed to be moved but now when it is moved the selected piece disappears from the board completely ingorning all the new function in the mouse release event
The code I am trying to add is for the WhitePawn which is the only piece that should be allowed to move right now
The rest if they are tried to move should just return to there set positions regardless of where they are dragged. I have removed all code not relevant to the question and ran the debugger. From that I know a fact that the problem is somewhere in the mouse release event code, I just cant find it.
public void mouseReleased(MouseEvent e) {
if (chessPiece == null) {
return;
}
chessPiece.setVisible(false);
Boolean success = false;
Component c = chessBoard.findComponentAt(e.getX(), e.getY());
String tmp = chessPiece.getIcon().toString();
String pieceName = tmp.substring(0, (tmp.length() - 4));
Boolean validMove = false;
//Pawn Moves
//White Pawn
if (pieceName.equals("WhitePawn")) {
if (startY == 1) {
if ((startX == (e.getX() / 75)) && ((((e.getY() / 75) - startY) == 1) || ((e.getY() / 75) - startY) == 2)) {
if ((((e.getY() / 75) - startY) == 2)) {
if ((!piecePresent(e.getX(), (e.getY()))) && (!piecePresent(e.getX(), (e.getY() + 75)))) {
validMove = true;
} else {
validMove = false;
}
} else {
if ((!piecePresent(e.getX(), (e.getY())))) {
validMove = true;
} else {
validMove = false;
}
}
} else {
validMove = false;
}
} else {
int newY = e.getY() / 75;
int newX = e.getX() / 75;
if ((startX - 1 >= 0) || (startX + 1 <= 7)) {
if ((piecePresent(e.getX(), (e.getY()))) && ((((newX == (startX + 1) && (startX + 1 <= 7))) || ((newX == (startX - 1)) && (startX - 1 >= 0))))) {
if (checkWhiteOponent(e.getX(), e.getY())) {
validMove = true;
if (startY == 6) {
success = true;
}
} else {
validMove = false;
}
} else {
if (!piecePresent(e.getX(), (e.getY()))) {
if ((startX == (e.getX() / 75)) && ((e.getY() / 75) - startY) == 1) {
if (startY == 6) {
success = true;
}
validMove = true;
} else {
validMove = false;
}
} else {
validMove = false;
}
}
} else {
validMove = false;
}
}
}
if (!validMove) {
int location = 0;
if (startY == 0) {
location = startX;
} else {
location = (startY * 8) + startX;
}
String pieceLocation = pieceName + ".png";
pieces = new JLabel(new ImageIcon(getClass().getResource(pieceLocation)));
panels = (JPanel) chessBoard.getComponent(location);
panels.add(pieces);
} else {
if (success) {
int location = 56 + (e.getX() / 75);
if (c instanceof JLabel) {
Container parent = c.getParent();
parent.remove(0);
pieces = new JLabel(new ImageIcon(getClass().getResource("WhiteQueen.png")));
parent = (JPanel) chessBoard.getComponent(location);
parent.add(pieces);
} else {
Container parent = (Container) c;
pieces = new JLabel(new ImageIcon(getClass().getResource("WhiteQueen.png")));
parent = (JPanel) chessBoard.getComponent(location);
parent.add(pieces);
}
} else {
if (c instanceof JLabel) {
Container parent = c.getParent();
parent.remove(0);
parent.add(chessPiece);
} else {
Container parent = (Container) c;
parent.add(chessPiece);
}
chessPiece.setVisible(true);
}
}
}
Image showing the folder layout of My build in case I have you can see somewhere that is not linked probably
Hopefully someone can see where I am going wrong, as I just want to get one piece moving before I split the pieces away from the board.java file completely into a new java file
I've looked through some of your code, again there's too much for me to go through in its entirety, but please let me give you some suggestions.
This is brittle/dangerous code:
JLabel awaitingPiece = (JLabel) c1;
String tmp1 = awaitingPiece.getIcon().toString();
if (((tmp1.contains("White")))) {
You're using an object's toString() representation as part of your code logic which is something you should never do. You're also doing String manipulations on the String returned, and again using the returned String for code logic,
Component c = chessBoard.findComponentAt(e.getX(), e.getY());
String tmp = chessPiece.getIcon().toString();
String pieceName = tmp.substring(0, (tmp.length() - 4));
Boolean validMove = false;
again something that is dangerous to do.
Instead, you could get the Icon and compare for Icon equality via the equals(...) method. Even better though is to get your logic out of your GUI and into the Model section of your program. If you can fully separate concerns, you'll stand a much better chance of having smaller units of code that are much easier to debug for both you and for us.
Otherwise, to get a better more complete answer, you're still going to want to first work to isolate the error, and for that, I still recommend that you use an MCVE.
Also I see that you're checking if an Icon is named "WhitePawn"
chessPiece.setVisible(false);
Boolean success = false;
Component c = chessBoard.findComponentAt(e.getX(), e.getY());
String tmp = chessPiece.getIcon().toString();
String pieceName = tmp.substring(0, (tmp.length() - 4));
Boolean validMove = false;
//Pawn Moves
//White Pawn
if (pieceName.equals("WhitePawn")) {
When in actuality I'll bet that it's named something quite differently. Since your Strings are playing a key role in your program (too great a role, I fear) are you debugging your String values to see why the code doesn't work?
For instance, a few println's could do wonders:
chessPiece.setVisible(false);
Boolean success = false;
Component c = chessBoard.findComponentAt(e.getX(), e.getY());
String tmp = chessPiece.getIcon().toString();
String pieceName = tmp.substring(0, (tmp.length() - 4));
System.out.println("pieceName is: " + pieceName); // ******* Added ********
Boolean validMove = false;
Myself, I'd not use Strings for this but rather would use enums, something you know will be stable and will be exactly what you assume it to be.
I am a beginner at programming and I have been teaching myself as much as I can. I need help in a simpler way of checking for a victory instead of hard coding every possible combination.
I have no idea what to do.
here is my current code:
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class connectfour extends JFrame implements ActionListener
{
JLabel board[][] = new JLabel[8][7];
//JLabel board[] = new JLabel[64];
JButton action[] = new JButton[8];
JButton start;
JButton clear;
JFrame Frame = new JFrame();
ImageIcon red = new ImageIcon("red piece.jpeg");
ImageIcon black = new ImageIcon("blackpiece.jpeg");
boolean players = true;
//Integer[] numclick = new Integer[8];
int x;
int numclick1 = 7;
int numclick2 = 7;
int numclick3 = 7;
int numclick4 = 7;
int numclick5 = 7;
int numclick6 = 7;
int numclick7 = 7;
int numclick0 = 7;
public connectfour()
{
Frame.setSize(100,120);
Frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
Frame.setLayout(null);
Frame.setVisible(true);
start = new JButton("Start");
start.setBounds(0,0,100,100);
start.setVisible(true);
start.addActionListener(this);
Frame.add(start);
}
public void game()
{
for(int x = 0; x < 8 ; x++)
{
action[x] = new JButton();
action[x].setSize(100,40);
action[x].setLocation((x*100) + 50, 0);
action[x].addActionListener(this);
action[x].setVisible(true);
Frame.add(action[x]);
}
/**
board[1][1] = new JLabel();
board[1][1].setBounds(50,40,100,100);
board[1][1].setVisible(true);
board[1][1].setOpaque(true);
board[1][1].setBorder(BorderFactory.createLineBorder(Color.black));
Frame.add(board[1][1]);
**/
for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 7; j++)
{
board[i][j] = new JLabel();
board[i][j].setSize(100,100);
board[i][j].setLocation((i*100)+50,(j*100)+40);
board[i][j].setOpaque(true);
board[i][j].setVisible(true);
board[i][j].setBorder(BorderFactory.createLineBorder(Color.black));
Frame.add(board[i][j]);
}
}
clear = new JButton("Clear");
clear.setBounds(850,100,100,50);
clear.addActionListener(this);
clear.setVisible(true);
Frame.add(clear);
}
public void boardsize()
{
Frame.setSize(950,800);
}
public static void main(String args[])
{
new connectfour();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == start)
{
boardsize();
start.setVisible(false);
game();
}
for(x = 0;x < 8 ;x ++)
{
if(e.getSource() == action[x])
{
//numclick[x]++;
if(x == 0)
{
numclick0--;
if(players == true)
{
board[x][numclick0].setIcon(red);
players = false;
break;
}
if(players == false)
{
board[x][numclick0].setIcon(black);
players = true;
break;
}
}
if(x == 1)
{
numclick1--;
if(players == true)
{
board[x][numclick1].setIcon(red);
players = false;
break;
}
if(players == false)
{
board[x][numclick1].setIcon(black);
players = true;
break;
}
}
if(x == 2)
{
numclick2--;
if(players == true)
{
board[x][numclick2].setIcon(red);
players = false;
break;
}
if(players == false)
{
board[x][numclick2].setIcon(black);
players = true;
break;
}
}
if(x == 3)
{
numclick3--;
if(players == true)
{
board[x][numclick3].setIcon(red);
players = false;
break;
}
if(players == false)
{
board[x][numclick3].setIcon(black);
players = true;
break;
}
}
if(x == 4)
{
numclick4--;
if(players == true)
{
board[x][numclick4].setIcon(red);
players = false;
break;
}
if(players == false)
{
board[x][numclick4].setIcon(black);
players = true;
break;
}
}
if(x == 5)
{
numclick5--;
if(players == true)
{
board[x][numclick5].setIcon(red);
players = false;
break;
}
if(players == false)
{
board[x][numclick5].setIcon(black);
players = true;
break;
}
}
if(x == 6)
{
numclick6--;
if(players == true)
{
board[x][numclick6].setIcon(red);
players = false;
break;
}
if(players == false)
{
board[x][numclick6].setIcon(black);
players = true;
break;
}
}
if(x == 7)
{
numclick7--;
if(players == true)
{
board[x][numclick7].setIcon(red);
players = false;
break;
}
if(players == false)
{
board[x][numclick7].setIcon(black);
players = true;
break;
}
}
System.out.println(x);
System.out.println();
}
}
if(e.getSource() == clear)
{
for(int x = 0; x < 8; x++)
{
for(int y = 0; y < 7; y++)
{
board[x][y].setIcon(null);
numclick1 = 7;
numclick2 = 7;
numclick3 = 7;
numclick4 = 7;
numclick5 = 7;
numclick6 = 7;
numclick7 = 7;
numclick0 = 7;
players = true;
for(int j = 0; j < 8 ; j++)
{
action[j].setEnabled(true);
}
}
}
}
if(numclick0 == 0)
{
action[0].setEnabled(false);
}
if(numclick1 == 0)
{
action[1].setEnabled(false);
}
if(numclick2 == 0)
{
action[2].setEnabled(false);
}
if(numclick3 == 0)
{
action[3].setEnabled(false);
}
if(numclick4 == 0)
{
action[4].setEnabled(false);
}
if(numclick5 == 0)
{
action[5].setEnabled(false);
}
if(numclick6 == 0)
{
action[6].setEnabled(false);
}
if(numclick7 == 0)
{
action[7].setEnabled(false);
}
}
public void winner()
{
}
}
I would use a recursive method that checks the horizontal, vertical, and both diagonals.
As i was reading your code I realized you don't keep track(may have missed it) of where players are.. I recommend and array for this called grid[][] Mapping an array to your JLabels will go a long way.
Ill give an example of negative vertical check..
public Boolean checkVertical(Boolean player, int x, int y){
if(solveHelper(player, x, y, -1, 0) => 4) return true;
return false;
}
public int solveHelper(Boolean player, int x, int y, int addX, int addY){
if(x == 0 || x == size || y == 0 || y == size || grid[x][y].player != player)
return 0;
return solverHelper(player, x+addX, y+addY, addX, addY) + 1);
}
Now how can you create and use these methods for yourself?
you need to create a new methods for each of the horizontal, vertical, and both diagonals to check for all of them you call solveHelper with different properties in addX and addY that correspond with the direction you want to go. For instance, if you want to check the horizontal you need do make addY == 1 and addY == -1 with both values for addX == 0 by doing a solveHelper + solverHelper with these two values changed.
Other notes...
Some things you need to need to keep in mind is that how connect four actually runs. When you click on a row a piece falls down to the smallest unoccupied element in that particular column. Just something you should keep in mind when writing your game logic.
Cheers.
I'm having a problem getting the screen to change to the image I want to display.
The image is a spritesheet which is set up as an array ( ie first screen is in array index 0 etc...)
I can change when I press the UP key and LEFT key and ENTER key, but the program will not display the correct image pressing the DOWN key.
I eventually want to discard the arrow key presses and subsituite them for numbers (the phone number keys ) 4 to return, 1,2,3 to go to certain pages and enter to go to the next page, if there is more information on a particular page.
private void actOnKeyStates(int k) {
if ((k & DOWN) != 0) {
Title = false;
HowToPlay = true;
Controls = false;
About = false;
}
if ((k & UP) != 0) {
Title = false;
HowToPlay = false;
Controls = true;
About = false;
}
if ((k & LEFT) != 0) {
Title = true;
HowToPlay = false;
Controls = false;
About = false;
}
if ((k & FIRE_PRESSED) != 0) {
Title = false;
HowToPlay = false;
Controls = false;
About = true;
}
update();
}
public void update() {
if (Title) {
Screen.setFrame(0);
}
if (HowToPlay) {
Screen.setFrame(1);
}
if (Controls) {
Screen.setFrame(4);
}
if (About) {
Screen.setFrame(5);
}
}
I would appreciate any advice on the matter.
First I think it would be better if you established a state for your game, rather than just using an increasing number of boolean values. Such as this:
public enum ScreenState { Title, HowToPlay, Controls, About }
private ScreenState currentScreen = ScreenState.Title;
private void actOnKeyStates(int k) {
if ((k & DOWN) != 0) {
currentScreen = ScreenState.HowToPlay;
}
if ((k & UP) != 0) {
currentScreen = ScreenState.Controls;
}
if ((k & LEFT) != 0) {
currentScreen = ScreenState.Title;
}
if ((k & FIRE_PRESSED) != 0) {
currentScreen = ScreenState.About;
}
update();
}
public void update() {
switch(currentScreen) {
case Title:
Screen.setFrame(0);
break;
case HowToPlay:
Screen.setFrame(1);
break;
case Controls:
Screen.setFrame(4);
break;
case About:
Screen.setFrame(5);
break;
}
}
The second thing you need to do is confirm that k & DOWN is being executed correctly when the DOWN arrow is pressed. Also confirm that the image you are looking for is correctly placed in the position 1 in your sprite sheet.