2D Tile Game Lag (Caused By Loop) - Rendering All Tile Rectangles

Jan 18, 2014

So the following is my code for the Terrian Generation of my game, however the way i have it rendering all the tile rectangles as opposed to just rendering whats visable on my JFrame causes lots of lag.

These are the variables and Rectangles inside _TerrianGen.class

//CHUNK
static int chunkx =2048;
static int chunky =2048;
 
//RECTANGLES
public static Rectangle[][] tile = new Rectangle[64][64];
static int[][] blockType = new int[64][64];
//0=Grass 1=Dirt 2=Stone 10=Brick 11=Coal 12=Iron 21=Gold 22=Diamond -1=null

This is the Init() code

for (int x =0; x < chunkx-32; x+=32){
for (int y=0; y < chunky-32; y+=32){
tile[y/32][x/32] = new Rectangle(x, y, 32, 32);
blockType[y/32][x/32] = -1;

[Code] ....

View Replies


ADVERTISEMENT

2D Game Tile

Dec 16, 2014

When the tile loads it loads at the side where i wanted it to be and when my character falls down the image/tile stretches to the collision and stops. looks like this stretches.jpg

The character codes:
error.jpg

And for the Level:
error2.jpg

View Replies View Related

Modern Gems - Two Dimensional Tile-management Game

Feb 20, 2014

package modern.gems;
public class Board {
// will need to add params where required ...
private Gem[][] gems;
private int[][] array;
private int rows;
private int cols;

[Code] ....

View Replies View Related

Tile Scrolling Engine Won't Render Properly

Oct 5, 2014

So I can only get 1 tile to render Okay so now it's no tiles Nvm.

Window
import java.awt.BorderLayout;
import java.awt.HeadlessException;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;

[code]....

View Replies View Related

Tile Based Map Editor - Organize Layout

Apr 13, 2014

I'm trying to program a tile-based map editor and most of it is going quite smoothly except trying to organize the layout. Originally I was going to use 2 frames, one for the map, and 1 for the tile set, but after reading about frames I learned that that is bad practice and is also inconvenient because there is no way to have both frames in focus at once (so you need to click an extra time to gain focus when switching windows). So what I'd like to do is create a single frame application that holds 3 panels. One for the map, one for the tile set, and one for tile settings. This is basically what it would look like:

Note that the tile settings panel uses GUI elements (a border, a JLabel (which starts out empty), a JComboBox, and a JTextField) while the other 2 panels are just drawing panels*

Now I have tried multiple things which either did not work visually (panels were inside panels) or did not compile. One thing I tried was using BoxLayout to put the 2 tile panels vertically within a temporary panel which I then tried to add into the frame after the map panel (with FlowLayout), but that made it look like this: I honestly don't know what else I did that I should write here because in retrospect many of the tings I tried were silly or I don't remember exactly what I did. What would be the best layout to doing what I want?

View Replies View Related

String Out Of Bounds Caused In While Loop

Jul 24, 2014

The code is supposed to insert HTML formatting on a specified string. (i.e o<b>the</b>r )Most of the code works correctly as I verified the outputs without a while loop. The loop is causing a string out of bounds error. I've tried adding the if statement and also formatting the (result += line) nothing is getting appropriate results...

public static String addFormat(String webpage, String toMatch, String format) {
String result = "";
String insert = "";
format = format.toLowerCase();
switch (format){
case "bold":
insert = "<b>" + toMatch + "</b>";

[code]....

View Replies View Related

Broken Loop - Number Guessing Game

Jun 3, 2014

What's wrong with my code. It says 'you win' even when I guess an incorrect number. And then the 'win' message keeps repeating. I'm thinking I need a way to generate a new input? And then maybe take the 'win' message out of the loop, but that breaks it too.

View Replies View Related

Guessing Game Demo - How To Add DoAgain Loop

Apr 8, 2014

Ok, here's what I got.
 
import java.util.Random;
import java.util.Scanner;
 
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
 
public class demoGuessGame { 
public static void main(String[] args) {
Random any = new Random();
Scanner input = new Scanner (System.in);
try {
  int maxNum, maxTries, guess;
boolean win = false;
 
[Code] .....

I want to make it loop again when asked, "Do you want to play again?"

View Replies View Related

Game Loop Freezing - Reset Button To Clear Board

Nov 9, 2014

I'm back with a question about the Black Jack assignment. I've created a working game that works for one round, as well as a reset button that's able to clear the board of the old hand. However the runGame() loop, which checks whether a player has played his hand seems to freeze the program the second time around

private void initNewGame(){
dealer.addCard();
for(int i = 0; i < numberofplayers; i++){
players[i].addCard(); //draws card, adds score and paints card to the board
players[i].setStatus(false); //makes the buttons usable in the players[] class

[Code] .....

I know it's probably not optimal having an while loop constantly running to check the status, but I can't seem to figure out why it freezes.

View Replies View Related

Two Rectangles Overlap

Oct 27, 2014

the thing with this program is that instead of it having preset variables, I want to prompt the user to enter values of the two rectangles. I don't know how to use the scanner in this case, or even if I should use the scanner.

class MyRectangle2D {
//declare the variables
private double x, y;
private double width, height;

[code]...

View Replies View Related

How To Make 2 Rectangles In Same Window

Oct 2, 2014

My goal is to make 2 rectangles in the same window. so far I have this.

import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class BoxComponent extends JComponent

[Code] ....

After running the program I get one rectangle, the red one. If I take the code out for the red rectangle, I only get 1 blue one. What am I missing?

View Replies View Related

Determine If Rectangles Cover Each Other

Oct 22, 2014

[URL] .... This is a link to the credentials that need to be met.

/* Constructors, getters and setters that will determine if the rectangles cover each other.*/

import java.util.Random;
import java.lang.Math.*;
class Rectangle{
   int width = 50;
   int length = 50;
   int x = 90;
   int y = 90;
  
[Code] ....

View Replies View Related

Drawing Rectangles From Array List

Nov 13, 2014

The program is where you will click anywhere in the jframe and it will draw a new rectangle. I have altered the code given to us but the problem that I am having is the fact that when I click the rectangle will always be connected to the upper left hand part of the jframe, no matter where I click. The program should create rectangles of the same length and width wherever you click. Here is what I have. I believe I have to change something in the addRectangle method, but nothing that I have tried works.

Java Code:

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
import java.util.ArrayList;
public class RectangleComponent2 extends JComponent

[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

Applets :: Drawing Ovals And Rectangles In JApplet With Two Separate Buttons

Apr 15, 2014

I'm not exactly sure what the draw button is supposed to do specifically, all i know is that it is supposed to draw both rectangles and ovals. The problem I am having is that when ever I click Draw Rectangle, it draws rectangles jusst the way I want but when ever I click Draw Oval, the program keeps drawing rectangles. I've tried repaint and clearRect methods but I did not manage to get them to work. I'm not sure what the problem is right here, I just cannot get it to work. Is there anything you guys can see that might be causing this? It's always good to have a different person look at it then myself. Also, I'm trying to implement a boolean for draw oval but I don't know where to put the if then.

public void init() {
length = new JTextField(10);
width = new JTextField(10);
btnDraw = new JButton("Draw");
btnClear = new JButton("Clear");
btnDrawRectangle = new JButton("Draw Rectangle");
btnDrawOval = new JButton("Draw Oval");

[Code] .....

View Replies View Related

Draw 3 Rectangles In Different Spots / Move Elements In Order So They Do Not Cross

Apr 9, 2014

I made a small aplication which draws 3 rectangles in different spots(0,0 , 50,50 , 100,100)

Am I used an KeyListener + ActionListener, to make them move in the let's call it box.

How can I do in order that those 3 elements do not cross, so you can always see them, they don't collapse into each other?

Java Code:

package matrixmoveelements;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

[Code] ......

View Replies View Related

Display And Resize Multiple Rectangles Independently - Using Objects From ArrayList

Jan 13, 2014

I have a code to resize a single rectangle. I would like to display and resize multiple rectangles independently and according to my research on the net, the best way is to use an arraylist. So I modified the code in this sense, except ...when I run the code, the rectangles appear good but impossible to resize. I think the problem comes from mousePressed, Released, Dragged and Moved methods. When I use the mouse to resize the rectangle, nothing happens. The code does not interact with the arraylist, and therefore with rectangles it "contains". Resizing is my main class, the MouseAdapter is in the Resizer class (below).

Resizing component;      boolean dragging = false;      // Give user some leeway for selections.     
final int PROX_DIST = 3;      Path2D.Double selectedPath;        public Resizer(Resizing rz) {         
component = rz;          component.addMouseListener(this);         
component.addMouseMotionListener(this);     

[Code] .....

View Replies View Related

Rendering Actions In A Combo Box?

Feb 2, 2014

When I add an array of action-objects (the class extends AbstractAction)

to a combo box, I do receive the action performed events, great!

But the combo box items show the long string of the action object, of course!

How to render that string in a way that only the Action.NAME appears?

I was experimenting a little, but could not make it to work:

Java Code: private class ComboRenderer2 extends BasicComboBoxRenderer {
@Override
public Component getListCellRendererComponent(JList list,

[Code]....

View Replies View Related

Rendering The Cells Of JComboBox In Java?

Aug 27, 2014

I have a student class with fields names and Gender. Now, I have a students' array. such that I can create multiple students' classes: student a, student b, student c e.t.c and store them into the students' array. Now, I store this students' array in a JComboBox and want to only display the names of these students in the array. Such that the JComboBox lists only the names of student a, student b and student c. . When a user clicks on a selected Item on the JComboBox, even though, it was a student's name that was selected, I want the selectedItem to be a object of the Student class. This, I have learnt works with JList by writing your own custom JList models and then DefaultListCellRenderer. Is there anyway, one could also do this with JComboBox?

//Main Method
import StudentList;
import Student;
import ViewGui;
import Controller;
public class SwingMainMethod {

[code]....

View Replies View Related

JSF :: CDI With Primefaces Charts Not Rendering Properly

Jun 3, 2014

I have 4 Primefaces bar charts which sometimes renders, sometimes not. In one of them, I inject a http user session attribute and use it to render the chart (the idea is to show only the data that corresponds to the (logged in) user department).

There are 4 session beans which I'm using the javax.enterprise.context.RequestScoped. Sometimes, the Glassfish destroys the instance as expected, but sometimes not.Based on Exception below, how can I resolve it?

The xhtml below shows the main code for only 2 of the 4 bar charts:

<p:tab title="Horas de Treinamento (por Funci)" closable="true" >
<p:barChart id="horasBars" value="#{chartHorasFunci.modelHoras}"
legendPosition="ne"
orientation="horizontal"
seriesColors="AA5555, 00438F"
xaxisLabel="Horas" yaxisLabel="Funcis"
title="34 Horas de Treinamento (Orçado/Realizado) por Funci"

[Code] .....

The Exception:

SEVERE: Error Rendering View[/capacitacao/capacitacao/index.xhtml]
javax.el.ELException: /WEB-INF/include/capacitacao/capacitacao/List.xhtml @145,38 value="#{chartHorasFunci.modelHoras}": org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke private void br.com.bb.upb.diage.atb.capacitacao.beans.ChartHorasFunci.initialize() on br.com.bb.upb.diage.atb.capacitacao.beans.ChartHorasFunci@3e9c727c
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)

[Code] .....

View Replies View Related

JSF :: Element Is Not Rendering / Parsing While Migrating

Jan 24, 2014

I m trying to migrate JSF 1.2 project with myfaces to JSF 2.0 with myfaces 2.0 jars on weblogic10.3 server. Found some problem related build and publishing after resolving them when i hitting my application all JSF html tags are coming in browser as it is they are parsed to html tags. all h: tages are coming as it is on my browser they are not converted to html tags for browser display.

View Replies View Related

JTree Branch Icon Rendering

Nov 12, 2014

I have a problem I must solve and could not find an answer after a couple weeks of research, so here I am. I have created a custom Table Cell Renderer than extends DefaultTreeCellRenderer. The mission of this renderer is to set the branch icons depending on conditional statements. There are 3 conditions, and each one should render a different icon. These conditions must be tested against all branches in the tree. This means that using something like setOpenIcon() and setClosedIcon() will not work since it seems as though these methods set all branches to a specific icon (I could be wrong about that though). Below is the code for my custom. I made comments so it is easier to understand what I want to happen and what is not happening.

/**Custom Cell Render that will set the icons for the tree branches and the leafs*/
private TreeIconCellRenderer extends DefaultTreeCellRenderer{
public Component.getTreeCellRendererComponent(JTree tree, Object value,boolean selected,boolean expanded, boolean leaf, boolean row, boolean hasFocus){
//Get defaults in case there is no need to renderer

[Code] ...

What I really need to know is why the renderer is not differentiating between the leaves and branches. The logging statements I have added confirm that the branch block of code does not execute.

View Replies View Related

JavaFX 2.0 :: Rendering Text Along A Curve

Nov 8, 2014

I'm currently working on a project which requires to have text displayed along a curve. If found this entry a good starting point. It works fine for me on my develompment machine, however the customer on his machine noticed some issues.

The basic idea is to define a path for the text, explode the text into the separate characters and animate them along the path the fraction of the character of the whole lenght. So with a animation duration of 10 seconds and a label of ten characters, the first character would be animated along 1 second, the second 2, and so forth.

This is done by jumping to the designated time in the animation, start the animation and stop it immediately.

Now the problem as I see it, for stopping the animation a separate timer is used, so it can happen that at the time the animation is actually stopped, the animation moved further than the first frame. The effect is that the last characters of the text appear in front (wrapped around).

As I have no evidence to prove or disprove my theory, what do you think is this plausable? I can see a workaround for this issue by defining a path for each character and then let the animation run to the end. While I can set the duration of the animation to 1 ms which should not be visible to the human eye, I'm not able to make the characters invisible and turn the visiblity on when the animation finishes, they always become visible at the start.

Or create my own animation/transition for placing the characters.

View Replies View Related

JavaFX 2.0 :: TreeItem And Custom Rendering

May 31, 2014

I am fairly new to FX but well experienced with Swing. Since I am familiar with the Swing concept of rendering a let's say JTree I got problems with the FX model of - in this case - TreeView.
 
I read several documentations about FX. From the API doc of TreeItem I adapted the file browser example to create an own class like this :
 
public class PathTreeItem extends TreeItem<PathTreeItem> implements
        Comparable<PathTreeItem> {
    private boolean firstVisit = true;
    private boolean readable;
    private boolean dir;
    private boolean symlink;

[Code] ...
 
But this did not change anything. I try to override toString() in both classes but even this did not change anything.
 
What I wonder so far:
 
Why is item in PathNodeTreeCell always null?What is the difference between the item I get in the updateItem method and the one I get from getItem() (line 10)How can I connect the PathTreeItem class to the PathNodeTreeCell classShould I always call super() in the constructors? (I delved a little bit in the sources of TreeItem and TreeCell and I found some setup code there )Is it ok to extend TreeItem in the way I does for my custom PathTreeItem class? ( I wonder if this is a cyclic dependency when I extends TreeItem in this way )How can I sort the nodes? I added the Comparable interface but this not change the sorting of the nodesAre ther some tutorials of TreeItem/TreeCell with no trivial objects like String ? 

I want to adapt an well running Swing application to FX. In the Swing app I used a mechanism to load the child path's of a directory in a separate thread to avoid freezing if the UI if there are much child elements. I guess in FX I should use the Properties pattern to achieve this should I?

View Replies View Related

JavaFX 2.0 :: Triangle Mesh Rendering

Aug 7, 2014

I'm new to JavaFX and I'm exploring its 3D capabilities, and in particular the TriangleMesh visualisation.
 
I have developed a very basic application, based on the Molecule Sample Application provided in the examples, that read a mesh file generated by an external tool (Gmsh) and displays it. Pretty basic.
 
My problem is that the rendering is not what I expected (see attachement)
  
My guess is that I got something wrong with the texture coordinates or the triangles orientation.

- I don't what to have textures attached to my meshes. These are 3D meshes used for scientific simulation purposes. I thus have set all texCoords to 0.
- I don't control the orientation of my triangles, they are generated by Gmsh. Their orientation is also not interesting for my end users so I would like to display all triangles the same way. I used the meshView.setCullFace(CullFace.NONE); method.

View Replies View Related

JSF :: Rendering A Page Using EJBs Between Separate Applications

Oct 16, 2014

I would like users in an application to be able to access and edit their user profiles (Application A). The problem is that the user objects (entities, dao, beans) are handled in a separate application (Application B) which is specifically for managing user accounts. Importing the java sources for App B into App A could be messy and might need configuration of the persistence unit and connection. I'm thinking it would be better to inject an EJB from App B to App A to query the user DB and return the results so a user profile form is rendered in App A.

I know how to inject EJBs within the same application, but I'm not so sure about how it's done across different applications or even if that's the most advisable way to achieve what I want. it's better practice to inject an external EJB into App A or simply import the classes from App B and use those.

@Stateless
public class UsersDaoImpl implements UsersDAO {
@PersistenceContext
private EntityManager em;

[code]....

View Replies View Related







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