How To Add Tiles To Screen

Mar 24, 2014

this is my first java game im making i tried to add tiles to the screen but i just get a black screen with no errors?

View Replies


ADVERTISEMENT

Cardlayout Format - Change Main Menu Screen Into Game Screen On Button Click

Mar 16, 2015

I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so

Here is the code from my CardLayout:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;

[Code] ....

I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.

Here is the main important GUI from my CheckerBoard class:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
  public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
 
[Code] ....

Once again kept to a minimal.

View Replies View Related

Error While Moving The Tiles In Frame

Jan 17, 2014

I was following a tutorial on how to make a game when i suddenly got an error concerning moving tiles. i get this error when i tried to use a and d to move:

Exception in thread "Display" java.lang.ArrayIndexOutOfBoundsException: 48600
at com.cherno.graphics.Screen.render(Screen.java:44)
at com.cherno.Game.render(Game.java:124)
at com.cherno.Game.run(Game.java:87)
at java.lang.Thread.run(Unknown Source)

I do not get the error while using w or s but the tiles are still not moving when pressing them.

I have three classes at work here.

The main, Game.java;

package com.cherno;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;

[Code] .....

View Replies View Related

2D Game - How To Create A Library Of Tiles

Apr 8, 2014

So I'd like to make like a library of tiles, and it isn't too big, which I could just call using a method, and I would specificy what information I need to get, and it would return that information.

For example, a small section of the tiles library is grass_tile, I call this library and specify what I need, and in this case let's say I need the width, or can the character enter it from north? or can the character just stand on it? So it's like a library or array, with sections of it being named by tiles, and by mentioning these tiles I can information about them.

gTile("grass","walkon") will return true, first because I specifiy grass, and yes the character can walk on grass, so it returns a boolean value of true.

gTile("stone","width") will return 16, first because I specify stone, and the stone's png image size is 16.

What I'm asking is not for how to work out if the character can walk on the tile, or read the width of a tile, but can I create like a library from which I can obtain information by giving the name of the tile, and then telling it what info I need.

If up key pressed && gTile((yTILE + 1).name(),"walkon") == true then moveChar("up")

View Replies View Related

Scrabble Been Able To Match 7 Random Tiles From ArrayList

Nov 25, 2014

I am trying to do here is to get as many words as we can to match words from the text file giving the 7 random letters from the arraylist ...

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;
public class Scrabble {
public static Scanner scan = new Scanner(System.in);

[Code] .....

View Replies View Related

LibGdx / Box2D - How To Group Tiles Into One Larger Polygon

Jan 19, 2015

I am making a tile based top-down 2D RPG and am using Box2D for the physics. Since my game is tile-based, there are many tiles on each map that cannot be moved through. This results in many small individual Box2D bodies. This is obviously very inefficient and makes the game lag. Therefore I figured that combining the individual tiles' bodies into larger complex groups would be better.

The way I thought of doing it is to, first, group together tiles into groups of tiles that all share 2 vertices with at least one other tile in the group. Then, for each group I do the following. First I get all of the uncommon vertices (these should be the ones on the outside of the polygon). Then I connect all of those vertices and then remove all of the overlapping lines. This should result in only lines on the outside of the polygon. Then I sort the lines so that the first line in the sorted array shares its end point with the second line's start point, etc. Then I remove the doubled vertices and using those remaining vertices (I called them the "true vertices") I create the polygon. I know that Box2D only supports convex polygons, but with Box2DSeparator I should be able to do this, but I first want this method to actually work.

/**
* Attempts to combine the given blocks into larger bodies to improve performance.
* @param bs The created wall blocks.
* @param w The world. Used for body creation.
*/
private void makeLargeBodies(Block[][] bs, World w) {
Array<Tile> tiles = new Array<Tile>();
for(int i = 0; i < bs.length; i++) {

[Code] .....

However, this is where the first problem arises. This method is extremely slow for large maps (like 200x200 tiles). I have worked at this for very long and right now my head can't figure out how to make the loop more efficient...

Now for the next part. After that I attempt to create the bodies for the TileGroups:

//create all the groups' bodies
size = groups.size;
System.out.println(size + " groups");
for(int i = 0; i < size; i++) {
TileGroup g = groups.get(i);
System.out.println("Starting group " + i + ".");
long timeCheck = TimeUtils.millis();
g.createBody(w);
System.out.println("Group 0 took " + (TimeUtils.millis() - timeCheck) + " millis");
}

*Note that the printing is for debugging purposes*...

This method is probably not a problem; it is what is inside createBody(World) that is the issue...

public void createBody(World w) {
Array<Vector2> allVertices = new Array<Vector2>();
Array<Vector2> uncommonVertices = new Array<Vector2>();
System.out.print("Starting search for uncommon vertices. ");
long timeCheck = TimeUtils.millis();

[Code] .....

Most of the code is self-explanatory (with comments). My current issue is where I connect the uncommon vertices (see the printed statements). This method does not actually finish (I have let it run for several minutes and it does not complete). This is likely due to a large number of vertices (often around 3000 in a 60x60 map), but I cannot figure out how to make the loop more efficient... Because of this early failure I don't know if the rest of the method works, both physically and in theory.

All relevant classes (Tile, TileGroup, Line) are below:

private class Tile {
private Vector2[] vertices;
private TileGroup group;
public Tile(int x, int y) {
vertices = new Vector2[4];

[Code] ....

View Replies View Related

Collision Detection Using Rectangles - Player Sometimes Passes Through The Tiles

May 19, 2014

I have already tried every possible way for removing this bug but all failed. The problem is that sometimes my player passes through the map tiles, i mean, the algorithm is like -- if not colliding, move in required direction; else if colliding, move in opposite direction. But sometimes the second condition fails i dont understand why.

private void movement(){
left=bindObject.getLeft();
right=bindObject.getRight();
up=bindObject.getUp();
down=bindObject.getDown();
bindObject.setColliding(colliding);

[Code] .....

Where bindObject is a class which contains key bindings of following keys:-

left arrow key (when pressed) , left arrow key (when released),
right arrow key (when pressed), right arrow key (when released),
up arrow key (when pressed), up arrow key (when released),
down arrow key (when pressed), down arrow key (when released)

View Replies View Related

Calculate Possible Tiles Clicked Unit Can Be Moved On And Display It To Player

May 15, 2014

Alright, so I'm having problems with lines 11 - 55. I'm trying to calculate the possible tiles the clicked unit can be moved on and display it to the player.

The field is a 9 (columns) by 5 (rows) grid. A unit with can move tiles horizontally or vertically based on its movement.

Example: (unit = o; possible tiles = x) (assuming movement of 2).

[ ][ ][ ][ ][x][ ][ ][ ][ ]
[ ][ ][ ][x][x][x][ ][ ][ ]
[ ][ ][x][x][o][x][x][ ][ ]
[ ][ ][ ][x][x][x][][ ][ ]
[ ][ ][ ][ ][x][ ][ ][ ][ ]

I tried to calculate movement by finding out what column the unit is in, subtracting the column it wants to go to, multiplying the difference by *-1 if the difference is less than 0. Then, doing the same with rows and adding the difference of columns to the difference of rows and comparing it to the unit's movement. Unfortunately, with my code, it seems to move in any directions.

@Override
public void mouseClicked(MouseEvent e) {
if (Main.cards.size() > 0) {
mainloop: for (int i = 0; i < Main.cards.size(); i++) {
Card c = (Card) Main.cards.get(i);
int startingColumn = 0;

[Code] ......

View Replies View Related

How To Clear Console Screen

Apr 2, 2014

How to clear console screen ? I am using Linux machine.

1) Runtime.getRuntime().exec("clear"); // this is not working. Not clearing the screen

2) for ( int i = 0; i < SOME_NUMBER; i++)
System.out.println();

2nd way is working but i think it is not a good option as i need to move scroll bar again and again.

View Replies View Related

JSF :: How To Force Refresh Screen

Oct 9, 2014

in my JSF2 app I have ​​screens composed with :

- Header
- Body

In the header I have a combo list. At each change in value in the combo list I have an Ajax request that updates the data in the Body. So far everything is working properly. Now the home screen's structure should be change when the value of combo list change. To do this I have :

- 1 ManagedBean HomeBean that manage the home
- 1 ManagedBean HeaderBean that manage the header
- 2 object HomeScreen1.java and HomeScreen2.java that allows me to valued data from each screen
- 2 services HomeScreen1Loader.java and HomeScreen2Loader.java that manage loading of each type of screen
- 1 template home.xhtml
- 2 fichier home1.xhtml et home2.xhtml

When I log in to the application, I get the good page corresponding (Element type 1 => home page 1). But when I select a type 2 item, the actionListener methode is execute, ManagedBean's data was updated (for type 2 screen) , but the page does not updated. What do you do ?

HeaderBean.java :

package com.omb.view;
import java.io.Serializable;
import java.util.List;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

[Code] .....

View Replies View Related

Adding Selector On The Screen

Jan 30, 2014

I was working on adding a selector on the screen. Searching for code, I found something that some created better than I ever could. I'm trying to integrate it into my code.

I have a program that is pretty MVC.

I'm in my controller class and I'm calling this code:

java - Drawing a bounding rectangle to select what area to record - Stack Overflow

I've changed it to a runnable and called a wait after I called this class, but it still continues on to the next line.

I'm thinking I'll have to either create a super controller (one that manages two controllers and have a multiple set of views and models) because I'll have multiple views or I'll have to figure out how to wait for it to finish as a thread. As mentioned above, wait() doesn't work.

This is the code in my controller after I changed it back from a Runnable:

SelectionRectangle m_rect = new SelectionRectangle();
//Thread m_thread = new Thread(m_rect);
//m_thread.start();
TopLeft = m_rect.getTopLeft();
BottomRight = m_rect.getBottomRight();
C_view.setText(TopLeft.toString());

View Replies View Related

Disabling All Screen Buttons

Apr 29, 2014

I'm having an issue with a swing application I'm working on. Java version is 4 (I know...). I have a main screen panel with multiple sub-panels (rows). Each of these row panels contains an additional 2 sub-panels. One of these 2 sub-panels contains buttons. When 1 button is pressed, I want to disable all of the buttons on-screen (or any other way of blocking user input) until a background event finishes. The row panels do not know about each other.

The first thing I have tried doing is, when a button is pressed, getting the parent. Using the parent I then iterate through its components, and so on until I'm iterating through the buttons. For each button, I am doing a .setEnabled(false); However, this does not work, why. I've also tried wrapping this process in SwingUtilities.invokeLater() out of desperation, but that didn't work either.

What would be the cleanest way to disable all buttons? Or block all user input? I've also tried adding an opaque dialog which hasn't worked. Last resort would be maintaining some sort of button list, but I'd rather not.

View Replies View Related

Add Up 4 Numbers And Print Out On Screen

Jan 20, 2014

I just started taking a Java class and i'm having problems with this code,

I'm trying to add up the 4 numbers have them print out on screen.

public class finalGrade
{
public static void main(String[] arg)
{
double pLp = 28.3; //Participation, lab work, and programming

[Code] .....

View Replies View Related

JavaFX 2.0 :: Access Screen From The Web?

May 16, 2014

how to access my rrmLogin from the web?
 
With JSP can do? How do it? or exist other way? or: [URL] ....
 
I tested (i need some configuration): [URL] .... but this method download the jar file (and other libraries) right? and the program act same as a Desktop app, right?

View Replies View Related

Swing/AWT/SWT :: Screen Resolution / Size

Sep 29, 2014

I have created a java gui on Windows 7 with Eclipse EE, using a screen resolution of 1366 x 768. I used groups with specified boundaries. For example:

final Group g5_script_data = new Group(shell, SWT.BORDER_SOLID);
g5_script_data.setText("Current DB");
g5_script_data.setBounds(0, 0, 680, 380);
g5_script_data.setBackground(green);

The groups cover the whole screen.

However my colleague with a smaller resolution looses the far right of the screen.

As this is a proto-type and I'm new to Java I don't want to rework everything or convert it to say a grid layout until the proto-type is accepted and I can start from scratch with a real detailed design. It already has 6500 lines of source.

Just wondered what is my quickest/easiest way to get my app to display on a slightly smaller resolution. For sure it will not be anything silly. Something like 1280 x 768 to 1366 x 768 would do.

View Replies View Related

Drawing Image On To Screen - Nothing Appears?

Feb 7, 2014

I am trying to draw an image unto the screen, however, nothing appears...

Java Code:

private ImageIcon i = new ImageIcon("image.png");
private Image image;
...
image = i.getImage();
...
g.drawImage(image, (int)(x - r), (int)(y - r), null); mh_sh_highlight_all('java');

Am I doing it right? The program gives me no error, it's just that when I try to draw it, I see nothing.

View Replies View Related

Bullets Not Firing Across Network Screen

Apr 10, 2014

I have a program thats ran over a network and is multi-player. However whenever I fire any bullets they do not fire on the other clients screen. Here's the code

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.util.*;
public class TankWar {

[Code] ....

View Replies View Related

Replicate IPad Touch Screen?

Jan 30, 2015

Haven't used java in a long long time and firstly need to know if its possible to build an app to replicate my ipad touch so that I can loop it between two different points on the screen. Friend recommended I got netbeans to get me started but wanted to ensure its possible before I get started.

View Replies View Related

Swing/AWT/SWT :: How To Make GUI Look The Same On All Screen Resolutions

Feb 11, 2015

I had developed small GUI using swing group layout, which is nice to see on windows, but when I tried it on Linux the GUI look is varied. Then I set the GUI height and width by taking screen resolution, still it is varies the screen look. How I can make the GUI such that it looks the same on all screen resolutions.

View Replies View Related

Getting Enemies To Spawn Off Screen Randomly

Sep 22, 2014

I am making a game and i am trying to have enemies spawn slight off the screen and randomly each time the game is run. I can get them to spawn randomly but i cant seem to get them off the screen properly ( when i do they take too long to enter the screen).
here is the code

for(int b = 0; b < GamePanel.enemy_amount; b++){
GamePanel.enemy.add(new Enemy((int)(Math.random() * 4000),(int)(Math.random() * 200)));
}

here is the width and height of the JFrame

setSize(1200, 800);

View Replies View Related

Scaling Text According To Screen Size

Jul 4, 2014

What I am creating is a clock. That goes round n round using "getcalendar". It's realtime, but the clock has a constant resolution of 800x800. I have carefully placed numbers from 1-12 on the clock using that resolution placing them pixel by pixel. Now if I resize the window, the clock resizes but the text, it fades away out of the screen because the resolution is too small.

This is how I draw them.

g2.drawString(six, 380, 750);
g2.drawString(twelve, 375, 70);
g2.drawString(nine, 30, 415);
g2.drawString(three, 725, 415);
g2.drawString(one, 570, 120);
g2.drawString(two, 690, 250);
g2.drawString(four, 685, 575);
g2.drawString(five, 570, 700);
g2.drawString(seven, 200, 710);
g2.drawString(eight, 80, 585);
g2.drawString(ten, 80, 235);
g2.drawString(eleven, 205, 115);

I understand why this is happening, obviously because the strings are in a certain place just can't understand how do I make them scaleable? Is there an universal formula? Or do I have to draw every string relevant to some mathematical equation regarding to the screen size.

For example : g2.drawString(twelve, diameter / 2, screenheight / 3);

View Replies View Related

Swing/AWT/SWT :: How To Update The Table On Screen

Mar 11, 2014

I'm writing my first bigger program (mysql connection and the first thing bigger than 300 lines ). What I'd like to do is to render data from MySQL using JTable - I managed to handle all the queries but I don't know how to update the table on screen. I've tried to use repaint() but nothing happened. I'm not posting whole code because you'll probably not interested, below are the most important things. I thought about using TableModel but how.

public class Main implements ActionListener{
JTable table;

public Main() {
JFrame frame = new JFrame("Frame");
frame.setLayout(new FlowLayout());
frame.add(table);

[code]...

View Replies View Related

How To Position 8 Objects Across Middle Of Screen

Oct 18, 2014

I am trying to draw add flowers on a graphics window. I can do this just fine, however the position starts from the far left and goes to the far right. I would like to position the 8 flowers in the center of the screen but can't seem to get the right formula to do so. Here is what I have so far to draw the flower, which is simply a GOval nothing complex:

Java Code:

box.flowers=8;
for (int xpos1 = 10; xpos1 < getWidth() - 40; xpos1 += getWidth() / box.flowers) {
box.drawFlowers(xpos1, 400);
} mh_sh_highlight_all('java');

The box size of the window is 800 by 600. Ideally I would like to place x amount of flowers spread across the middle of the screen. How might I do this???

View Replies View Related

Bouncing Ball Around The Screen - It Keeps Disappearing

Oct 23, 2014

I'm trying to do is get this ball to bounce around the screen and ive gotten so far but not sure how to proceed. The ball keeps disappearing.

//bouncing ball

float x; //ball x position
float dx = 3; //ball x direction is right, step 5
float y; //ball y position
float dy = 3;
void setup () //runs once at start

[Code] ....

View Replies View Related

JavaFX 2.0 :: How To Add Screen Builder To Eclipse 4.2.2

May 29, 2015

I want to include JavaFX in my Eclipse IDE.  I found intructions on how to import JavaFX Screen Builder into Eclipse 4.4 but my version is 4.2.2
 
I noticed that JavaFX is included into Java JDK now, I have installed Java JDK 8_45
 
The info on the oracle java pages is telling me i have to install JavaFX Screen Builder 2 before installing the plugin.
 
So, how to i proceed ???
 
I tried to inport e(fx)clipse plugin 1.2 and 0.9 but both refuses to install.  Messages received as follows:
 
Cannot complete the install because one or more required items could not be found.

  Software being installed: e(fx)clipse - IDE - FXML 1.2.0.201501301049 (org.eclipse.fx.ide.fxml.feature.feature.group 1.2.0.201501301049)
  Missing requirement: JavaFX Preview 1.2.0.201501301049 (org.eclipse.fx.ide.ui.preview 1.2.0.201501301049) requires 'bundle com.google.inject 2.0.0' but it could not be found
  Cannot satisfy dependency:
    From: e(fx)clipse - IDE - FXML 1.2.0.201501301049 (org.eclipse.fx.ide.fxml.feature.feature.group 1.2.0.201501301049)
    To: org.eclipse.fx.ide.ui.preview [1.2.0.201501301049]

View Replies View Related

Swing/AWT/SWT :: Dragging Window Downwards - Screen Alignment?

Oct 29, 2014

I am trying to drag the window down wards and screen has alignment issues. I tried to use WindowListeners, Component Listeners, MouseListeners ect…

But still this problem persists as only I release the mouse after drag down it appears fine that we have handled ComponentResized() method. So how to restrict component size while keep dragging down?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved