Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 3 ... 71
1  Game Development / Newbie & Debugging Questions / Re: Libgdx android xml saving on: 2014-09-18 13:16:59
Well, no stacktrace, no help Undecided It's just impossible to debug an error, if you don't have any information.

Also don't use static variables. The stuff they hold will never be collected by the garbage collector. Especially never hold anything outside of a method that you don't need outside of the method!
2  Discussions / General Discussions / Re: FlipFlop - Examn f(CLK) on: 2014-09-18 10:54:06
Think about it.  The NAND resets all flip flops every twelve ticks. The question is asking about the output of Q3. There is only one low->high flip for Q3 at the 9th tick (on that paper) ...

Now again - this does not??? affect the frequency of Q3 - really,  come on...  Tongue
3  Game Development / Newbie & Debugging Questions / Re: libgdx saving map on: 2014-09-17 15:37:50
Also you could try using kryo, but I don't know how good this works on android. But I would assume, that it works good enough, since the author also was a core contributor to libgdx.
4  Game Development / Newbie & Debugging Questions / Re: libgdx saving map on: 2014-09-17 15:35:31
Just looked up the source. XmlWriter directly writes through to the given writer object, so nothing is stored. Post your source again.
5  Game Development / Newbie & Debugging Questions / Re: libgdx saving map on: 2014-09-17 15:12:10
Just change it to

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  
package com.hawk.engine.game.xml;

import java.io.IOException;
-import java.io.StringWriter;
+import java.io.Writer;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.XmlReader.Element;
import com.badlogic.gdx.utils.XmlWriter;
import com.hawk.engine.game.level.Level;
import com.hawk.engine.game.level.Tile;

public class XMLMap {

-   private static XmlWriter xml;
-   private static StringWriter writer;
-   private static FileHandle file;
   
   public static void saveMap(String name){
-      writer = new StringWriter();
-      xml = new XmlWriter(writer);
-      file = Gdx.files.local(name);
+      FileHandle file = Gdx.files.local(name);
+      Writer writer = file.writer(false);
+      XmlWriter xml = new XmlWriter(writer);

      try {
         //int whatisit, int blockID, float x, float y, float width, float height, Vector2 velocity, boolean hasCollision, boolean object, int objectID
              for(int i = 0;i < Level.lengthX;i++){
                  for(int j = 0;j < Level.lengthY;j++){
                     
                     Tile t = Level.tiles[i][j];
                     xml.element("t").attribute("w", t.getBlockDef()).attribute("bID", t.getBlockID())
                     .attribute("x", t.getX()).attribute("y", t.getY()).attribute("wi", t.getWidth()).attribute("he", t.getHeight()).attribute("vx", 0).attribute("vy", 0)
                     .attribute("co", t.isCollision()).attribute("o", t.isObject()).attribute("oID", t.getObjectID());
                  }
               }
         
         
-               file.writeString(writer.toString(), false);
      } catch (IOException e) {
         e.printStackTrace();
      }
+      finally {
+         try { writer.close(); } catch (Exception ignore) { /*ignored*/ }
+      }
   }
}

6  Game Development / Newbie & Debugging Questions / Re: libgdx saving map on: 2014-09-17 15:03:21
Doing 200x200 tiles as xml will probably result in a 10-20mb string. Don't know how the xml builder you are using handles that internally and if file.writeString() might create a copy of that. Best bet is to increase the heap to see if it works then or if there is some kind of memleak and use a memory profiler to inspect the size of the actual used memory and if it is stored/copied redundantly.

Can't you use the xml builder you are using with an FileOutputStream, so you skip the intermediate string in memory completely?
7  Game Development / Newbie & Debugging Questions / Re: libgdx saving map on: 2014-09-17 14:55:14
well, increase heap then Smiley
8  Discussions / General Discussions / Re: Java 8 Default Methods and Multiple Inheritance on: 2014-09-15 16:11:26
This also makes me wonder what happens if two interfaces define the same default function...?

You'll get a compilation error and are required to implement the method. You can then explicitely delegate to the default implementation you want to use.

Edit: Sometimes I think I am invisible...  persecutioncomplex
                    VVV
9  Game Development / Performance Tuning / Re: Check for null or check for implementation? on: 2014-09-15 10:40:42
Because I see Interfaces used as components right here in this thread Cheesy
Actually it's the oposite way around. Entity systems use components as replacement for interfaces Tongue
10  Game Development / Performance Tuning / Re: Check for null or check for implementation? on: 2014-09-15 07:50:18
It's in both lists because Entity would be the most generic type in this example and Drawable is a subset. So if you want to do something with all entities you would iterate only the entities list. This makes more sense, if you have more subsets, especially if they might overlap partly, so you can't just iterate over all lists to so something with all entities once.
11  Game Development / Performance Tuning / Re: Check for null or check for implementation? on: 2014-09-14 18:01:21
I actually like instanceof, especially when designing object hierarchies. I never got why so many people try to work around it. It's quite straight forward and easy to just ask an object what it is to decide what to do with it. Why would you not want to use such an important attribute of an object like it's type?

Having said that, the OPs problem is easy to solve by just calling
entity.draw(batch)
on any type of entity and implement the
draw(batch)
empty for entities not having a sprite... I doubt that using the null-check to prevent calling an empty method will boost performance significantly for any kind of game we are doing here.

I would do it different though (using instanceof). Something along the lines of:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
class World
{
    List<Entity> entities=new ArrayList<Entity>();
    List<Drawable> drawables=new ArrayList<Drawable>();

    add(Entity e) {
        entities.add(e);
        if(e instanceof Drawable)
            drawables.add((Drawable)e);
    }

    draw(Batch batch){
        int l=drawables.size();
        for(int i; i < l; i++)
            drawables.get(i).draw(batch);
    }
}


You can do this kind of specialized "caches" with all kind of "filters" that create more or less static lists of objects you need to iterate over and handle type (or otherwise) specific. The only downsides are slightly increased memory foodprint (multiple references to the same object) and some performance overhead for adding and removing objects to/from multiple lists.

I really can't see, why this kind of desing is bad practice, inperformant or "stinks".  
12  Game Development / Newbie & Debugging Questions / Re: Is it Possible to use Java and send sounds through the microphone? on: 2014-09-12 12:54:39
Using a speaker or headset in an unpowered microphone jack does not harm it. Dont know about phantom powered iinputs. Using a microphone as speaker probably would harm it.
13  Discussions / Miscellaneous Topics / Re: How to call police/ambulance from a different country on: 2014-09-12 12:49:47
Probably just call your local police hotline and let them forward the request.  Other than that google for emergency phone numbers and the international access code of the country in question.
14  Game Development / Newbie & Debugging Questions / Re: Is it Possible to use Java and send sounds through the microphone? on: 2014-09-11 21:50:03
Using speakers as microphones is actually possible and as easy as just connecting the speaker to the mic input...

If mics would produce sound if connected to a speaker out would probably depend on the type of mic – and of course on the wattage you try to put through  Grin
15  Game Development / Newbie & Debugging Questions / Re: Is it Possible to use Java and send sounds through the microphone? on: 2014-09-11 14:03:46
Why do you want to do this in java? If you want to create a soundboard, thats easy enough by just implementing sound playing when pressing on buttons. But simulating a microphone in java is not directly possible.

Just use the existing skype/os feature or google and install "virtual audio devices" to wire up a mixer.
16  Game Development / Game Mechanics / Re: Entity Component Manager on: 2014-09-10 06:42:27
You can do exactly the same in java. component_class would be of type Class and then you can pass in Position.class.
17  Game Development / Newbie & Debugging Questions / Re: How to port a java game to android on: 2014-09-09 08:19:07
Don't try to port it. Just rewrite it using LibGDX. Doing the "same" the second time is just good practice...
18  Discussions / General Discussions / Re: Performance Test for the Voxel Thing on: 2014-09-08 01:01:32
Min:340 Max:400
Intel i5-3570K@3.4GHz
8GB RAM
GeForce GTX760@1084MHz 2GB GDDR5
Windows 7

Animation was not fluid though. Looked more like a 30Hz gameloop.
19  Discussions / Miscellaneous Topics / Re: What I did today on: 2014-09-07 15:26:08
If you like Trackers,  take a look at Renoise
20  Game Development / Newbie & Debugging Questions / Re: How do you use Math.sin and Math.cos on: 2014-09-06 20:49:54
Take a look here:
http://www.java-gaming.org/topics/bullet-shooting-in-mouse-direction/34029/msg/320617/view.html#msg320617
21  Game Development / Newbie & Debugging Questions / Re: [SOLVED] Return int from Method (derped) on: 2014-09-06 20:42:24
I always recommend everyone here to learn using debuggers - they offer much more and faster means to find problems than System.outs (which have their uses).

Glad you solved the problem. What was it?
22  Game Development / Newbie & Debugging Questions / Re: Inheritance and arrays on: 2014-09-06 20:38:38
But that would mean that the base GameObject would need to have every method of every extended object.
This is actually a common "challenge" when designing game objects using inheritance. It comes down to put the most common methods into the root
GameObject
class and if you need more special ones you need to ask the object if it is of the desired type and then cast it accordingly:
1  
2  
GameObject current=objectMap[12][32]:
if( current instanceof Enemy ) ((Enemy)current).beNasty();

What comes handy is, that
instanceof
is not only true when the object is exactly of the desired type, it is sufficient to be an inherited type or an implemented interface, too. So if you have a subclass of
Enemy
like
EnemyTower
, it would also qualify as an
Enemy
for the
instanceof
test, and the above code would execute beNasty() on an
EnemyTower
instance.
23  Game Development / Newbie & Debugging Questions / Re: [SOLVED] Return int from Method (derped) on: 2014-09-06 20:18:33
If you havent already, make yourself familar with a debugger and place breakpoints on all locations where the value is written and inspect the value of the variable. The value will not magically change,  so you have some buggy code changing the value somewhere.  Should be easy to find with a debugger.

If you find spelling mistakes you can keep them this time Wink Or you can show me your german spelling typing on a phone...
24  Game Development / Newbie & Debugging Questions / Re: Return int from Method on: 2014-09-06 10:00:09
Some conventions never outweigh OCD. If I'm ever in a position to release a open source project, The chumps using it will have to suffer as do I.
While you can do what you want, it might be a good idea to adhere to some nameing conventions like having classnames start uppercase and use propper named getters and setters for accessing properties. Simple for the fact, that IDEs support refactoring and code navigation then. Also there are templating, scripting and component libraries/frameworks that use reflection to access properties and might rely on the fact that getters and setters are named as expected.

Also I don't know if being ignorant qualifies as OCD Tongue
25  Game Development / Newbie & Debugging Questions / Re: Where do normals come from? on: 2014-09-01 21:42:30
google: http://fullonsoftware.co.uk/snippets/content/Math_-_Calculating_Face_Normals.pdf
26  Game Development / Newbie & Debugging Questions / Re: Lost my CODE! on: 2014-08-14 12:00:38
I guess from the screenshot that you use Eclipse, so tried the Local History feature? I don't use Eclipse, so I don't know how long its' history lasts...
27  Game Development / Newbie & Debugging Questions / Re: Lost my CODE! on: 2014-08-14 11:45:18
Wait, you never saved that file in 2 weeks?

I'm sorry, but that's just silly!
No - the file just got corrupted. I have the same problem with my work PC. I get a blue screen on it from time to time and then every open file is filled with binary nulls...
Unfortunately this also happens to my locally cloned git repo - So any non-pushed changes are also lost Sad

I was going to release it as a WIP today too D:  Cry . Deep down Inside I know I put in  a LOT of work but for some reason...
Get over with. This might actually not be that bad at all. Redoing something that you already did just helps you practice and usually results in cleaner code anyway. So see this as an oportunity and not as a problem.

Back in the days when I started programming I always started from scratch and so basically memorized all the 68k assemly code you need to write an Atari ST overscan demo with side scrolling text and raster interrupt colorizing without even looking up interrupts, adresses or clock cycles.  Cool
28  Game Development / Newbie & Debugging Questions / Re: Bullet shooting in mouse direction on: 2014-08-05 20:31:03
Some more info
o you need to understand 2d vectors
  -> they are variables with an x and an y component and can be used to do stuff like described in the link above
o you need to understand the difference between vectors and points
  -> technically they look the same (having x and y), but logically they are different (a point is a position, a vector represents direction and length)
o you need to understand game loops
  -> the loop that periodically calls your update and render methods
o you need to understand what a timestep is
  -> the time period between your update calls
o you need to understand fixed and variable timesteps
  -> fixed timesteps are locked. For example to 1/60s.
o fixed timestep is easier for animating your game
  -> but the gameloop needs to make sure of it by variable sleep times to wait before the next gameloop iteration
o you need to understand when to use floats vs. ints
  -> only use ints for final rendering. use floats (or doubles) for variables needed in computation or to store (varying) positions

regarding your question:
o you need a direction vector pointing from the turret to the mouse
  -> it's easily calculated by substracting the turret position from the mouse position (and normalize the result)
o you need a speed variable containing the pixels per timestep
  -> the amount of pixels the bullet should fly per frame
o you need a bullet position variable that adds up the direction*speed*timestep per update call
  -> this needs to have float components

pseudo code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
// assume this values
float timeStep=1f/60f;
float turretX=10f;
float turrety=10f;
float bulletSpeed=3f; // speed is 3 pixels per second

// if a bullet is fired it is initialized like this
float bulletX=turretX;
float bulletY=turretY;

// and you need to calculate the direction vector for it's movement
float dirX= getMouseXFromSomeWhere()-turretX;
float dirY= getMouseYFromSomeWhere()-turretY;
// you need to "normalize" the direction vector to be able to use the speed variable
float dirLength= Math.sqrt(dirX*dirX + dirY*dirY);
dirX=dirX/dirLength;
dirY=dirY/dirLength;

// now on every update, you can add up the direction * speed * timestep to the bullet
bulletX=bulletX+(dirX*bulletSpeed*timeStep);
bulletY=bulletY+(dirY*bulletSpeed*timeStep);

// on every render, you can render the bullet sprite at that position
g.drawImage(bulletImage, (int)bulletX, (int)bulletY, null); // rendering often uses ints for coordinates


as you can see, standalone x and y variables are just the components of vectors grouped by a naming convention, so you could also use a vector class for that:

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  
// some minimal vector class
class Vec
{
    public float x, y;
    public Vec(float x, float y)
    {
        this.x=x;
        this.y=y;
    }
    public normalize()
    {
        float l=Math.sqrt(x*x + y*y);
        x/=l;
        y/=l;
    }
}

// since vectors and points look technically similar, you can "abuse" a vector to store positions:
Vec turret= new Vec(10f,10f);

// creating the direction vector
Vec dir=new Vec(getMouseXFromSomewhere(),getMouseYFromSomewhere());
dir.x-=turret.x;
dir.y-=turret.y;
dir.normalize();

// initializing a new bullet
Vec bullet=new Vec(turret.x, turret.y);

// animate the bullet on update...
bullet.x+=speed*dir.x*timeStep;
bullet.y+=speed*dir.y*timeStep;

// render the bullet sprite
g.drawImage(bulletImage, (int)bullet.x, (int)bullet.y, null);


Of course you can add more methods to the Vec class to make the code using vectors look more concise...
29  Game Development / Newbie & Debugging Questions / Re: Bullet shooting in mouse direction on: 2014-08-05 19:41:55
Please, people, learn vector math...
http://www.wildbunny.co.uk/blog/vector-maths-a-primer-for-games-programmers/
30  Game Development / Newbie & Debugging Questions / Re: StateMachine, Java Generics issue on: 2014-07-29 10:10:54
State<?>
http://docs.oracle.com/javase/tutorial/java/generics/wildcards.html
Pages: [1] 2 3 ... 71
 

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

The first screenshot will be displayed as a thumbnail.

BurntPizza (15 views)
2014-09-19 03:14:18

Dwinin (33 views)
2014-09-12 09:08:26

Norakomi (58 views)
2014-09-10 13:57:51

TehJavaDev (81 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (63 views)
2014-09-08 06:06:29

BurntPizza (46 views)
2014-09-07 01:13:42

Longarmx (33 views)
2014-09-07 01:12:14

Longarmx (38 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!