How To Make Smoother Movement

Jan 23, 2014

First, I have a figure that moves around the screen. It uses keylisteners and just subtracts or adds pixels. However, I notice the movement is not smooth at all. It is very rigid and laggy movement. How can I make it smoother movement?

Second, you get three lives in the game. The lives are subtracting correctly, but I want the game to say "GAME OVER" on a dialog box. How would I get this to happen? My JFrame and my life int are in separate classes. I know I should use an if statement, saying if lives are at or less than zero, open the box, but how do I open the box?

Third, I want to display the time on the screen. I have a swing timer, but how do I put it on the screen? DrawString is not working for me.

Fourth, I want to set an icon for the game, the code is running, but not doing anything.

Java Code: frame.setIconImage(Toolkit.getDefaultToolkit().getImage("/Users/MW/Downloads/petericon.jpg")); mh_sh_highlight_all('java');

View Replies


ADVERTISEMENT

Make Mouse Cursor Visible On Movement

Mar 25, 2014

I've been creating a digital clock using Java, and have made the mouse cursor invisible after a set period of time (40-seconds) and had the thought to make it visible again if mouse was moved.

Here's the code that makes it invisible:

ActionListener mouseTimeout = new ActionListener() {
public void actionPerformed(ActionEvent e) {
setCursor(blankCursor);
}
};
/* Make mouse cursor disappear after 40 seconds */
Timer mTimeout = new Timer(40000, mouseTimeout);
mTimeout.start();

And here is what I have so far for making it visible again:

MouseMotionListener mouse = new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e)
{
}
@Override
public void mouseMoved(MouseEvent e)
{
}
};

I have tried using "setCursor(DEFAULT_CURSOR)" but NetBeans says that it "cannot find symbol" .....

View Replies View Related

Mouse Movement Code

Feb 11, 2014

I have been working on this mouse movement code that detects which direction the mouse moves in hope to use it in a game. The only problem is that I can not figure out how to make it move to the other side of the screen so I could continue turning to the right or left without having to stop. How would I actually get the x and y coordinants of the mouse to change?

PHP Code: if(x == xscreen){
//set x to 0
}else if(x == 0){
//set x to xscreen
}else if(y == yscreen){
//set y to 0
}else if(y == 0){
//set y to yscreen
} mh_sh_highlight_all('php');

View Replies View Related

How To Do Movement In Text Based Game

Feb 13, 2015

I'm relatively new to Java, I'm trying to create a text based game, like those old ones where you type "north" or "east" to move as such, and "look" to inspect the area. My only problem thus far has been trying to figure out just how I should... "structure?" the movement. As in, what's the best overall way to approach this? I've tried making a new method for every area and just passing a variable called "location," but along with passing the inventory and stat arrays, it's just become messy. Or is this a good way to do it? I have a separate method for when the player enters something, but then how will it know which description to give when the player types "look?"

View Replies View Related

Unexpected OpenGL Simple Movement

May 28, 2014

I am new to DreamInCode! I was creating a game using OpenGL (and slick for textures).

Using Vector3f, I make coordinates to where my camera is camera'ing (and rotation).

It was working... until I modified something. I only added shaders. When I took the shaders off I think I might of accidentally deleted something. Nonetheless the code looks perfect to me.

On the method "input()" everything runs. No errors are thrown anywhere. I have syso'd the hell outa my code. It shows no signs of breaks. I can, however, move elements I put into my program. I am 100% sure that no other class is breaking my game (soon to be).

What you should look out for: I am not really sure about the glLoadIdentity()'s and glMatrixMode(). I am, knowing a good part of, thinking it could be gluViewPort....

My problem: Can't move my camera even tho it was working before.

package com.Hydroque.OpenGlTest;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluPerspective;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;

[Code] ....

View Replies View Related

Snake Game Movement Algorithm

Jun 16, 2014

I am working on replicating this project: [URL] ....

What is wrong with the moveSnake method and the for loop within it?

View Replies View Related

Limit Object Movement Within A Window

Aug 31, 2014

I just started to learn Java. In my program, I created a GRect(paddle) and I would like to move it on the x axis whenever the mouse is moved.

import acm.graphics.*;
import acm.program.*;
import acm.util.*;
import java.awt.*;
import java.awt.event.*;
public class BreakoutClass extends GraphicsProgram {
/** Width and height of application window in pixels */
private static final int WIDTH = 400;
private static final int HEIGHT = 600;

[code]....

In this case, whenever the paddle reaches the right edge of the screen, it doesn't move off the windows, but it stops moving (even if you move the mouse).

View Replies View Related

Matrix Icon / Button Movement

Apr 30, 2015

I'm working on making a game in JAVA. To be brief, the game is on a 6x6 matrix called "blocks[][]". The game has two players and the objective is to capture the enemies pieces by moving your piece onto there's. The players do this by moving one piece per turn either forward/backward (Vertically) or right/left (horizontal) movements. Essentially checkers without jumps.I'm not very far into the development process here. So far I have the game board created and the pieces load by clicking the "Start" button (handled by the refresh function). However I'm having a few problems... Namely moving the pieces effectively at the moment.

Right now there's a lot to do:

(1) - Implement a turn system,
(2) - Only allow a player to click their pieces (I've a validation function already in place to only permit valid moves [horizontal/vertical only]),
(3) - getting the pieces to actually "move" what I mean by this is a player selects the piece they want to move, then they select the spot they want to move to and the icon I have placed on the button is supposed to be added to the new square and the icon for its previous position is to be made null.

Please see the "actionPerformed" section to see exactly what I'm trying to do and hopefully as well see what I'm missing as to why it is not working at the moment... Also see under the Refresh function where I commented out the for loops to add the pieces. I did this because it was resulting in an ArrayOutofBounds error so I just wrote each spot out manually where I wanted them to start.

/* Ghosts *
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.border.*;
import java.io.*;

[code].....

View Replies View Related

Basic Sprite Character Movement

Aug 18, 2014

how I would go about having a moving sprite on a page, such as a virtual pet kind of thing. I've tried searching for it through the years and I've tried it with what I know on my own, but things just act up every time. Either:

A.) The sprite moves (respondent to key strokes, of course), but leaves a trail of its image behind itself.

B.) The background image writes, but for some reason the second image does not write, or is lost behind the background.

I'm sure these are simple issues for most of you, but I've tried going about this for a while now with no luck. What I'm trying to do I'm trying to write a virtual pet game, and I would eventually love to make it move around randomly like an A.I. that's pathfinding, but I've got ideas about that, just I need to know how to make it move period first, everything else I think I could figure out on my own.

View Replies View Related

Fading Trail And Random Movement Coding?

Oct 30, 2014

I need the following key controlled ellipse to leave a trail behind that vanishes after 10 frames. Also, I need to create a random moving ellipse not related to the preexisting one. How to separate the two ellipses ...

Current code:

boolean left, right, backward, forward;
boolean SPEED;
 PVector pos = new PVector(680, 400);
 void setup() {
size (680,400);
fill (0 ,0,0);
frameRate(100);
noCursor();

[Code] .....

View Replies View Related

Alien Movement In Space Invaders Game

Apr 13, 2014

I'm working on this space invaders game and I've been stuck trying to get the alien spaceships to move down in one group. The way we have to design the game is we have to implement at least these 3 classes. These classes are GameData,GamePanel, and Animator. GameData is all the action figures/models in the game. GamePanel draws all game action figures/ models on the screen. Animator updates periodicaly action figures positions,sizes, colors etc. I can get the aliens to move right but once they hit the end of the canvas I cannot figure out how to get them to move as a group down and then begin moving left. I tried to add alien objects to the GameFigures list and then have the update method in the Alien class be responsible for moving the alien ships, but I couldn't figure out how to make it work. So then I made an alienFigures list in the GameData class and I still cannot figure out what to do. Here is the GameData class

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

[code]....

View Replies View Related

Maze Game - Tracking Objects / Limit Movement

Jan 26, 2015

I made a kind of maze game that includes the class keylistener and orients a object, i can't find where the program tracks this object (where its x and y coordinates are). So now my object can move freely through all walls and i want it to bounce back or at least something to happen when the object reaches a wall.

I want to find a way to limit my objects movement and because i cant find where the coordinates or variable for this object is i cannot limit its movement

View Replies View Related

Swing/AWT/SWT :: Movement And Conversion Of GetText Input In OrderCalc Method

Mar 7, 2014

My OrderCalculator class is throwing an exception. The input from my HourPanel that is supposed to add to my OrderCalc is cooperating.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class OrderCalculator extends JFrame
{
private JobPanel jobs;
private HourPanel rate;

[Code] .....

View Replies View Related

JavaFX 2.0 :: Handle Table Column Re-position / Movement Event

Sep 4, 2014

How to catch the event when table view's column are re-positioned. Basically when the column is re-positioned from 1 position to 5 position ,  i want to do update the db.

View Replies View Related

Make Shapes Besides Making Two Lines For X And Oval With White Smaller Oval Inside To Make O

May 8, 2014

We are making a tic tac toe game for my CS120 class and I am having trouble figuring out how to make our X's and O's. Is there a way to make shapes besides making two lines for an X and an oval with a white smaller oval inside to make an O? We have only learned the basics so far in class (i.e. events, inheritance, client-supplier, etc.)

These are our instructions:

Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will 1) create a TicTacToeModel 2) create a TicTacToeView and 3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided (a view of the game, a button, and a text field to enter the cell). A sample screenshot is displayed below.And this is the code i have thus far:

[import java.awt.*;
import javax.swing.JFrame;
public class TicTacToeView extends Rectangle
public TicTacToeView(int x, int y, int w, int h) {
super(50,60,w,h);
this.setBackground(Color.red);
JFrame win = new JFrame("Tic Tac Toe");
win.setBounds(10,10,w+100, h+100);
win.setLayout(null);
win.setVisible(true);
win.setBackground(Color.gray);

[code]....

View Replies View Related

How To Make Palindrome

Aug 16, 2014

I want to ask how to make Palindrome in Java with 2 methods //Output is Like this

Input a word
Hey
Not a Palindrome
Reverse
yeH

View Replies View Related

Make Own Color To Use With Awt

Aug 22, 2014

I am stuck. I was trying to make my own Color to use with awt.

I used the statement :

public static final Color purple = new Color(255,0,255);

When I try to use Color.purple it says it cannot reference purple.

View Replies View Related

How To Make And Use A List

Nov 3, 2014

I first learned how to program with BYOB. In BYOB there were variables and lists. Variables worked the same as Java and lists were groups of variables. To create a list, I would give it a name. I could then add variables to this list as items throughout the program. Here's an example of what a list would look like:

[[List]]
item 1: Hello
item 2: world

I could then call upon item 1 or item 2 and delete them if needed. In Java, I want to have 3 lists of variables into which I put user input as variables. The code would look something like the following: (stuff with "//" at the end is detailing what I want to do, not actual working code)

import java.util.*;
public class Archives {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

How To Make Loop End

Feb 3, 2014

I do not know how to make the loop end. I think there is an issue with my second and thrid algorithms..Also its a commission calculator

--- Update ---

//Start Program
package commission;
import java.util.Scanner;
public class Commission
{

private static boolean saleTargetrange;

[code]....

View Replies View Related

How To Make Square Which Is Filled With (dot)

Oct 17, 2014

Do I want to make something like this:

*****
*.....*
*.....*
*.....*
*****

I am stuck, I have made a code that creates this and don't know how to complete it.

*****
* *
* *
* *
*****

Code:

class Main {
public static void main( String args[] ) {
System.out.print("#Enter number of stars :");
int stars = BIO.getInt();

[Code] ....

View Replies View Related

Using Text File To Make GUI?

Apr 16, 2015

I am currently in the progress of making a GUI for a project. I am trying to make a maze and I need it displayed in a GUI. So, I thought I would be able to do that with a text file that I created. The code I have for it so far runs and compiles but it is not displaying my text file as a GUI, even though it reads the file. All I get are a bunch of green rectangles. I am using Netbeans to code this

package rectangles;
import java.awt.Color;
import java.awt.Graphics;//this will draw the maze
import java.awt.Graphics2D;//
import java.io.BufferedReader;
import java.io.FileNotFoundException;//handles file

[code]....

View Replies View Related

Why Add Static To Make A Constant

Oct 30, 2014

public static final String NAME="JAVATAR";

"final" makes sure the constant has the same value and prevents it from being changed. So why add "static" to make it a constant. I figured the reason a few weeks back but don't remember it now.

View Replies View Related

Make A Pause Between Every Loop

Feb 18, 2015

I've been learning Java in school for lika a year now. Our teacher wanted us to make a game called "Game of Life" .Now it's not very optimized because the only type of GUI we know how to make it with JButtons so if I want a 100x100 grid that means the program has to load 10000 buttons and change text and color on them which I can imagen cause lags and so on but if we ignore that lagg our teacher wanted us to make it loop-able and well I kinda succeeded but the only problem is that I can't get it to wait between every loop so if I tell the program to loop 100 times, the program processes that and that takes forever and then updates the board and sometimes it takes forever and sometimes you cant even see the "cells" moving. Is it possible to get my program to loop and if so how? Here is the code:

//------------------------------------------------------------------------------------------------------------------------
// Hamta standardpaket
//------------------------------------------------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

[code]....

View Replies View Related

Make A Switch With A String

Jan 9, 2015

I needed to make a switch with a string ,but eclipse told met there was an error and that the fix was to switch to 1.7 compliant. I did so and now when i run my program errors come back.

Here are the errors :

Exception in thread "main" java.lang.UnsupportedClassVersionerror: start : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)

[code]....

View Replies View Related

How To Make JPanels Slide

Sep 25, 2014

I want to know how can I make a JPanel slide to to another JPanel (Slowly move to the next). I've made multiple JPanels so when I click on next it will take me to the next panel. Now I just need to add a nice transition to make my program look nicer. Is there an easy way to do it? or any way is fine I just want to add a transition ....

View Replies View Related

Trying To Make The Image Move

Oct 27, 2014

I am having trouble making my image move to a certain position in a certain amount of time which is set inside a text file. I was wondering what I'm doing wrong and what I'm missing.

import java.io.*;
import java.util.*;
import java.io.FileReader;
public class Animator {
EZImage HP;

[code]....

View Replies View Related







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