Show Posts
|
|
Pages: [1]
|
|
3
|
Java Game APIs & Engines / Java 2D / Re: rendering tiles w/ static render method
|
on: 2012-06-07 03:54:13
|
|
thanks for the tips, but I tried using startUse(), drawEmbedded() and endUse() but I still get some fps drops
it's not so much that I'm receiving low fps at the moment with my current rendering technique but the fact that if I want to call multiple render methods for every tile as an "object" the fps will drop insanely
|
|
|
|
|
10
|
Game Development / Performance Tuning / Re: fast box blur algorithm
|
on: 2012-03-24 03:28:46
|
|
I know this is an old thread, but generally:
int a = 0;
void derrfunction(){ ++a = 1; a++ = 0; }
it's incredibly asinine to argue about its speed though (like, it does NOT matter at all whatsoever), but it definitely feels better to know when to utilize the proper increment operators at any given time
|
|
|
|
|
16
|
Game Development / Game Play & Game Design / Re: smoother x/y-axis increments
|
on: 2012-03-18 04:05:47
|
... Or if you're using a 'double': 1 2 3 4 5
| public void move() { if (player.movingRight()) { player.absX = player.absX += 0.1; } } |
If that's not what you're looking for let me know. I am referring to faster increments of the x/y-axis. If you're using any sort of timer that updates (or allows updating) of the sprite position when time's up, then you can just use the speed of the sprite to calculate the new timer time. Each sprite would need it's own timer, but that's normal.
not sure how that would play out, maybe if I were to increase the time depending on how long the key is held? I'm mainly having trouble increasing the value by 1 fast enough so that I can move at a fast pace but still prevent choppiness it's like basically trying to scroll over 200 pixels when you could just increment by like 50 pixels and get there extremely quickly whereas you'd increment by 1 pixel very quickly and get there as quick (except not producing a choppy, 'bursty' travel)
|
|
|
|
|
17
|
Game Development / Game Play & Game Design / smoother x/y-axis increments
|
on: 2012-03-18 03:45:40
|
|
Is there a way to increment the x/y coordinates of a render smoothly by merely just incrementing it by 1 'faster'?
I've come across situations in which I am changing the speed/rate of travel of an object by just adding a larger value to the x/y coordinates of said object
so, something like
x += 5;
would make it appear to go faster but instead result in choppy rendering (since you're adding a large value like 5 instead of progressively adding values of 1)
in essence:
is there a way to 'speed up' incrementing by 1 (ie. ++x) in order to reduce choppiness when changing the rate of travel of an object?
|
|
|
|
|
19
|
Game Development / Newbie & Debugging Questions / Re: <List> add question
|
on: 2012-03-16 17:10:14
|
How is Screen.render being called? Are you using active or passive drawing on your component? If it is passive then you have to call repaint() on your root container.
Active (I didn't want to post the screen code because it shouldn't matter whether or not it appears but whether or not the entities.size increases) Where do you set removed to false? That could be the problem.
On definition removed is false, but it doesn't matter since I only want to see an increase in entities.size. If it works when entities is static but doesn't work anymore when it's not static then you must have more then one Screen object and you add the entity to the wrong one.
I don't know what you mean by that
|
|
|
|
|
20
|
Game Development / Newbie & Debugging Questions / <List> add question
|
on: 2012-03-16 02:43:56
|
I am trying to add a 'ball' entity with my mouse coordinates within my mouse class, however whenever I try to make a non-static reference in order to 'add' the ball it won't increase the entity size (not adding on the screen). Mouse.java: 1 2 3
| public void mousePressed(MouseEvent e) { s.addEntity(new Ball(e.getX(), e.getY(), 15, 15)); } |
Ball.java: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import java.awt.Color; import java.awt.Graphics;
public class Ball extends Entity{ private int x, y, width, height; private boolean removed; public Ball(int x, int y, int width, int height){ this.x = x; this.y = y; this.width = width; this.height = height; } public void render(Graphics g){ if(!removed){ g.setColor(Color.WHITE); g.drawRect(x, y, width, height); } } public void remove(){ removed = true; } } |
Screen: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import java.awt.Color; import java.awt.Graphics; import java.util.*;
public class Screen { public List<Entity> entities = new ArrayList<Entity>(); public void render(Graphics g){ System.out.println(entities.size()); for(int i = 0; i < entities.size(); i++){ entities.get(i).render(g); } } public void addEntity(Entity e){ System.out.println("ADDED" + e); entities.add(e); }
} |
Making entities static works, but there must be another way around this?
|
|
|
|
|
23
|
Java Game APIs & Engines / Java 2D / Getting rid of trails?
|
on: 2012-03-05 02:13:22
|
I know this is all related to double buffering and stuff but I'm trying to use createVolatileImage to draw some stuff on screen, however - there are trails being left behind. I've tried to get rid of them by clearing over the background image over the drawing but it doesn't work. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| package _game;
import java.awt.*; import javax.swing.JFrame;
public class _game extends Canvas implements Runnable {
*/ private Thread t = new Thread(this);
private boolean running; private static int width = 160; private static int height = 120; private static int scale = 4; public mouse mouse = new mouse(); private Screen screen = new Screen(); private long lastTime; public static int tick; public _game(){ int w = width * scale; int h = height * scale; setPreferredSize(new Dimension(w, h)); setMaximumSize(new Dimension(w, h)); setMinimumSize(new Dimension(w, h)); setBackground(Color.BLACK); addMouseListener(mouse); addMouseMotionListener(mouse); this.setFocusable(true); } public void start(){ lastTime = System.currentTimeMillis(); running = true; t.start(); } public static void main(String[] args){ _game ga = new _game(); JFrame frame = new JFrame("derr"); frame.add(ga); frame.pack(); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); ga.start(); }
public synchronized void stop(){ running = false; } public void paint(Graphics g) { }
public void update(Graphics g) { render(g); } public void render(Graphics g){
}
@Override public void run() { Image image = null; while(running){ tick = ((int)(System.currentTimeMillis() - lastTime)/100); if(image == null){ image = createVolatileImage(width * scale, height * scale); } Graphics g = image.getGraphics(); screen.render(g, mouse.mx, mouse.my); g = getGraphics(); g.drawImage(image, 0, 0, width * scale, height * scale, 0, 0, width * scale, height * scale, null); g.dispose();
try { Thread.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } } }
} |
screen.render(g) just draws rectangles at my mouse pos (when it is dragged)
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|