Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2
1  Game Development / Newbie & Debugging Questions / Re: Best way to iterate through ArrayList? on: 2014-10-17 13:09:31
What about:      for (Enemy e : getEnemies())  enemies.add(e);   Tongue
or even 133t:   enemies.addAll( java.util.Arrays.asList(getEnemies()) );
2  Game Development / Newbie & Debugging Questions / Re: Best way to iterate through ArrayList? on: 2014-10-17 13:00:15
For me it's either regular Array[], ArrayList or ArrayDeque:  persecutioncomplex
http://docs.oracle.com/javase/8/docs/api/java/util/ArrayDeque.html  
3  Game Development / Newbie & Debugging Questions / Re: Best way to iterate through ArrayList? on: 2014-10-15 16:56:55
Nah! Best quickest algorithm is this:   Tongue  

1  
2  
3  
4  
5  
for (int len = projectiles.size(), i = len; i-- != 0; )
  if (projectiles.get(i).removeCriteria()) {
    projectiles.set(i, projectiles.get(--len));
    projectiles.remove(len);
  }
4  Game Development / Newbie & Debugging Questions / Re: New Member Trying to Choose a Path on: 2014-09-25 23:40:53
Besides the aforementioned Processing: http://forum.Processing.org/two/discussions, there's Greenfoot too: http://www.Greenfoot.org/home.
5  Discussions / General Discussions / Re: Are Java applets really "dead" for indie developers? on: 2014-09-22 16:52:17
I would say GWT is equally dead :-)  It's a beast that even Google abandoned long ago.

Actually, GWT has become Dart: https://www.dartlang.org.   Wink 
6  Discussions / General Discussions / Re: Are Java applets really "dead" for indie developers? on: 2014-09-22 15:59:44
Processing also offers an approach to working in Java and deploying to JS, with 3D (WebGL) support - http://processingjs.org/

By default, it doesn't use WebGL! We've gotta pass P3D or OPENGL as the 3rd argument for size()!

7  Game Development / Newbie & Debugging Questions / Re: Did you know? Hints and tips on: 2014-07-14 22:31:24
For circle shaped objects:

1  
2  
3  
public boolean isColliding(Actor a) { // CIRCLE shapes.
  return sq(a.x - x) + sq(a.y - y) < sq(a.rad + rad);
}


1  
2  
3  
public static final double sq(double val) {
  return val*val;
}
8  Game Development / Newbie & Debugging Questions / Re: Did you know? Hints and tips on: 2014-07-14 22:23:50
Another good 1... Test for even or odd: (value & 1) == 0.
It's faster than value % 2 == 0!   Wink
9  Game Development / Newbie & Debugging Questions / Re: Did you know? Hints and tips on: 2014-07-14 22:21:39
I believe these versions are more succinct:   Roll Eyes  
P.S.: rx is w/2 & ry is h/2!

1  
2  
3  
public boolean isColliding(Actor a) { // CENTER coords.
  return x >= a.x-rx & x < a.x+rx & y >= a.y-ry & y < a.ry;
}


1  
2  
3  
public boolean isColliding(Actor a) { // CORNER coords.
  return x >= a.x & x < a.x+w & y >= a.y & y < a.y+h
}


10  Game Development / Newbie & Debugging Questions / Re: How to get the size of a primitive/object? on: 2014-07-12 21:37:20
According to the link I've provided, an object instance w/o any instance variables consumes 12 bytes.  
But due to 8 byte alignment, it jumps to 16 bytes. Also, generally we're gonna need to store its reference.
It means more 4 extra bytes. In short 16 bytes for each object at minimum + 4 bytes for each of its reference!   persecutioncomplex

1  
2  
3  
int bytes = 30;  // 12 overhead + 18 instance variables.
int align = (bytes-1)/8*8 + 8;
System.out.println(align); // 32 bytes consumed.
11  Game Development / Newbie & Debugging Questions / Re: How to get the size of a primitive/object? on: 2014-07-12 21:06:12
http://docs.Oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
http://Java-Performance.info/overview-of-memory-saving-techniques-java/
12  Game Development / Newbie & Debugging Questions / Re: For advice on where beginners should go to start making games on: 2014-07-06 19:47:43
Perhaps you should take a look at http://www.GreenFoot.org/doc or even http://Processing.org .   Smiley 
13  Game Development / Newbie & Debugging Questions / Re: [Solved] ConcurrentModificationException - How to avoid it on: 2014-06-25 20:11:11
Don't get me wrong, I love using the "enhanced" for-"each" loop version!
Even though it can be 10% slower for non-array structures than a c-style for loop! Grin
However, we can't use remove() on such loops. Either c-style or Iterator/ListIterator style for such occasions!  Roll Eyes
14  Game Development / Newbie & Debugging Questions / Re: [Solved] ConcurrentModificationException - How to avoid it on: 2014-06-25 07:36:55
I daresay that a backwards loop would still be a bit faster than an Iterator version.
B/c the condition is against a literal 0 rather than a method call like hasNext()!   persecutioncomplex
And the 2nd example using a remove()/set() combo is unbeatable! Averting left-shifting collateral is hard to ignore IMO!   Roll Eyes
On the other hand, if I was dealing w/ a structure like a LinkedList or similar, going w/ an Iterator or a ListIterator is a no-brainer!   Tongue
15  Game Development / Newbie & Debugging Questions / Re: [Solved] ConcurrentModificationException - How to avoid it on: 2014-06-24 23:46:28
I prefer this slightly more compact format using the faster overloaded index-based version of the remove() method:   Roll Eyes

1  
2  
3  
4  
5  
6  
for (int i = popups.size(); i-- != 0;) {
  PopUp p = popups.get(i);

  if (p.isDisposed())  popups.remove(i);
  else                 p.render();
}


And in the case the index order isn't important, this approach averts any left-shifting after remove(): Grin

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
for (int len = popups.size(), i = len; i-- != 0;) {
  PopUp p = popups.get(i);

  if (!p.isDisposed())  p.render();

  else {
    p = popups.remove(--len);
    if (i != len)  popups.set(i, p);
  }
}
16  Game Development / Newbie & Debugging Questions / Re: Teaching Java Game Programming to Children on: 2014-06-15 19:37:41
http://www.GreenFoot.org
https://www.KhanAcademy.org/cs
http://Hello.Processing.org
17  Game Development / Newbie & Debugging Questions / Re: Animated image that only exist for a short period of time. Garbage collection? on: 2014-05-20 01:49:50
Guess it's more specific saying assign null to every variable field or array "slot" which might happen to have a reference for the object we want to be disposed of later on!   Roll Eyes
Alternatively, rather than assign null to a variable, assign another object reference to it. The effect is the same!  Grin 
18  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Removing game objects on: 2014-05-12 02:18:49
Another option would be to have a Boolean in the entity isDead. When it collides with the player, you would set this to true. When you're updating and rendering then you would just ignore the enemies that are dead.

That's my favorite strategy! Although I prefer to save the "dead" object's index value
and then re-use it when requesting a new enemy rather than instantiate another 1!  Cool  

The other option is from this recent thread:
http://www.java-gaming.org/topics/concurrentmodificationexception-when-removing-an-item-from-an-arraylist/32939/msg/309008/view.html

If the order doesn't matter, remove the latest (tail) entry and insert it in the index of the "dead" object, replacing it!   Tongue
This way, we avoid left-shifting the List's entries completely! Shocked

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
static final int BULLETS = 100;
final List<Bullet> bullets = new ArrayList<>(BULLETS);

public void displaySpritesOptimized() {
  stroke(Bullet.COLOUR);
  for (int b = bullets.size(), len = b; b-- != 0;)
    if (bullets.get(b).script()) { // returns true if requesting remove due to outta canvas!
      final Bullet u = bullets.remove(--len);
      if (b != len)  bullets.set(b, u);
      System.out.println("A bullet has strayed too far from view!");
    }
}
19  Game Development / Performance Tuning / Re: Is there a logical reason to stuff 2D array data into one? on: 2014-05-06 16:04:55
Sure you save a couple of array lookups I guess, but I don't think the ry[] would assist much with caching (it's still a pointer).

That's the point, 1 pointer rather than 2! Moreover, values which don't change later in the inner loop are cached right in the outer loop!   Tongue  
20  Game Development / Performance Tuning / Re: Is there a logical reason to stuff 2D array data into one? on: 2014-05-06 15:17:35
Still you're not taking into consideration my tiny optimizations:   Lips Sealed  

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static void fill_2d_random() {
  for (int y = 0; y != DIM;) {
    int yi = randX[y++], ry[] = rows[yi], x = 0;

    while (x != DIM) {
      int xi = randX[x++];
      ry[xi] = yi^xi;
    }
  }
}
21  Game Development / Performance Tuning / Re: Is there a logical reason to stuff 2D array data into one? on: 2014-05-06 11:18:23
And for the non-random 2D fill too:   Cool  

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static void fill_2d_YX() {
  for (int y = 0; y != DIM;) {
    int yi = linearY[y++], ry[] = rows[yi], x = 0;

    while (x != DIM) {
      int xi = linearX[x++];
      ry[xi] = yi*DIM + xi;
    }
  }
}
22  Game Development / Performance Tuning / Re: Is there a logical reason to stuff 2D array data into one? on: 2014-05-06 11:06:28
Some cache optimization ideas for the random fill functions:   Roll Eyes  

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  
private static final int POW = 10, DIM = 1 << POW;

private static final int[] grid = new int[DIM*DIM];
private static final int[][] rows = new int[DIM][DIM];

private static int[] randX = new int[DIM], randY = new int[DIM],
                     linearX = new int[DIM], linearY = new int[DIM];

public static void fill_1d_random() {
  for (int y = 0; y != DIM;) {
    int yi = randY[y++], x = 0;

    while (x != DIM) {
      int xi = randX[x++];
      grid[yi<<POW | xi] = yi^xi;
    }
  }
}

public static void fill_2d_random() {
  for (int y = 0; y != DIM;) {
    int yi = randX[y++], ry[] = rows[yi], x = 0;

    while (x != DIM) {
      int xi = randX[x++];
      ry[xi] = yi^xi;
    }
  }
}
23  Discussions / General Discussions / Re: [Web Games] What is the best second language? on: 2014-05-01 12:34:22
As said, go w/ Dart or CoffeeScript!   Tongue 
24  Game Development / Newbie & Debugging Questions / Re: ConcurrentModificationException when removing an item from an arraylist on: 2014-04-28 05:38:01
If the order is not important, you can write your own list class that avoids all the overloads. Every time an element is deleted, you can overwrite the deleted item with the last item in the list, then decrease the list size counter. That way you can remove items without speed penalty and you don't need two lists, and all the copies that can be worse than the deletes. I have use this in my Retroships game and it works like a charm.

Loved your tip, Endos. I wish I'd known about that technique before! Although I didn't need to write my own List class at all.
A regular ArrayList is capable to pull that out. Check it out:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
static final int BULLETS = 100;
final List<Bullet> bullets = new ArrayList<>(BULLETS);

public void displaySpritesRegular() {
  stroke(Bullet.COLOUR);
  for (int b = bullets.size(); b-- != 0;)
    if (bullets.get(b).script()) {
      bullets.remove(b);
      System.out.println("A bullet has strayed too far from view!");
    }
}

public void displaySpritesOptimized() {
  stroke(Bullet.COLOUR);
  for (int b = bullets.size(), len = b; b-- != 0;)
    if (bullets.get(b).script()) {
      final Bullet u = bullets.remove(--len);
      if (b != len)  bullets.set(b, u);
      System.out.println("A bullet has strayed too far from view!");
    }
}
25  Discussions / Miscellaneous Topics / Re: new computer purchase advice on: 2014-04-02 07:23:09
@princec

I've also got some Linux distro advise which I've posted @ http://www.java-gaming.org/topics/sorry-ubuntu-has-experienced-an-internal-error/32616/view.html
But it's half digested by the "Chit-chat Monster" now though!   Undecided 

Luck I've saved my post offline and gonna re-post it here!   Roll Eyes 


Go to http://DistroWatch.com to get the picture of all open source distros.   Roll Eyes 

In general, any Ubuntu derived distro is good for 1st lookers.
As mentioned, Mint is overall the better choice. Zorin is good too.

But if you're inclined to more aesthetically gifted distros, I'd go w/:

    Elementary -> http://DistroWatch.com/elementary
    or Deepin   -> http://DistroWatch.com/deepin


For lighter Ubuntu-based distros, go w/:

    Bodhi -> http://DistroWatch.com/bodhi
    LXLE  -> http://DistroWatch.com/lxle


For non-Ubuntu & non-DebIan options, perhaps these 3 below:

    PCLinuxOS -> http://DistroWatch.com/pclinuxos
    Fedora       -> http://DistroWatch.com/fedora
    OpenSUSE -> http://DistroWatch.com/suse


If you feel pretty adventurous, there's PC-BSD -> http://DistroWatch.com/pcbsd
Which it's not even a Gnu/Linux distro, but a FreeBSD 1!   Tongue
26  Game Development / Newbie & Debugging Questions / Re: New to java, where do i start? on: 2014-03-05 00:05:09
BlueJ is a very nice beginner IDE:  http://bluej.org
27  Discussions / Miscellaneous Topics / Re: C++ standard library is really lacking - good or bad? on: 2014-03-03 05:17:59
If some1 wanna stay in the middle of both C++ & Java, D language mixes up both styles: http://dlang.org 
Like C++, it provides pointers & machine code compiling. Like Java, it offers GC, similar class definitions and transparent object variables!
28  Discussions / Miscellaneous Topics / Re: C++ standard library is really lacking - good or bad? on: 2014-02-27 17:05:42
Main difference between what Java/C# calls a reference & C/C++/D calls a pointer is that the latter includes memory addresses for everything that got 1.  
That is, references for variables & functions; not just objects!   Roll Eyes  
29  Discussions / Miscellaneous Topics / Re: C++ standard library is really lacking - good or bad? on: 2014-02-27 04:11:27
There's also the C++, Rust & Go rival, the D language -> http://dlang.org
Like Dart, it also implements classes & GC very Java like!   Grin  
30  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-18 02:51:29
1  
2  
3  
4  
5  
6  
public class Player extends Entity{
   
   FixtureDef fixtureDef;
   BodyDef bodyDef;
   Texture texture;
   PolygonShape shape;


I wonder if you are re-declaring Entity's fields within Player again?
Also, you said that both WORLD_TO_BOX & BOX_TO_WORLD were supposed to be constants. But they're instance variables after all!  Shocked
Pages: [1] 2
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (46 views)
2014-10-17 03:59:02

Norakomi (37 views)
2014-10-16 15:22:06

Norakomi (28 views)
2014-10-16 15:20:20

lcass (32 views)
2014-10-15 16:18:58

TehJavaDev (62 views)
2014-10-14 00:39:48

TehJavaDev (62 views)
2014-10-14 00:35:47

TehJavaDev (52 views)
2014-10-14 00:32:37

BurntPizza (70 views)
2014-10-11 23:24:42

BurntPizza (40 views)
2014-10-11 23:10:45

BurntPizza (82 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!