Im currently trying to program a little game (in Java - Libgdx; if thats necessary).  I currently use a GameWorld and a GameRenderer, the GameRenderer just getting all the info it needs from the GameWorld object and calling a method for every different class there is (for example drawPlayer(), drawWorld() etc.).   Should I let my actors draw themselves or encapsulate the data inside of another class and then pass an object of it to the GameRenderer?
51588
I am very new to game development, but not to programming.  I am (again) playing around with a Pong type game using JavaScript's canvas element.  I have created a Paddle object which has the following properties...   width height x y colour   I also have a Pong object which has properties such as...   width height backgroundColour draw().   The draw() method currently is resetting the canvas and that is where a question came up.  Should the Paddle object have a draw() method responsible for its drawing, or should the draw() of the Pong object be responsible for drawing its actors (I assume that is the correct term, please correct me if I'm incorrect).  I figured that it would be advantagous for the Paddle to draw itself, as I instantiate two objects, Player and Enemy. If it were not in the Pong's draw(), I'd need to write similar code twice.  What is the best practice here?  Thanks.
14089
I'm creating a function where I need to pass an object so that it can be modified by the function. What is the difference between:  public void myFunction(ref MyClass someClass)   and  public void myFunction(out MyClass someClass)   Which should I use and why?
25920
This is specifically about the development and planning direction of the game development.  I'm creating a fairly basic RPG and am wondering about the approach that I should take. I've been trying to outline it all in a flow chart first, but want to see if this is a good way of going about it.  For example, I've created a class called "items", which then currently derives into "Weapons" "Armor" and "Potions". I then derive these classes further into specific types and I keep going and going, basically as specific as I want to get.  Before I get too deep into this (again, I'm still planning) - I just want to know if this is a good way of approaching this problem.
110721
I'm starting to think about how I'm going to go about loading models, images, sounds, etc for my game. I have two competing lines of thought to deal with:   If possible, it would be nice to make use of existing libraries to load things like PNGs, etc. I would like to pack all of my game data into a single archive, and it would be great to use an existing library here also.   Is it possible to do this? I've heard that I could use something like zlib for (2), but I've never used it before so I'm not sure how it would work. Is it possible to yank a file out of a zlib archive in memory, and then pass it to some compatible library for the actual loading? How would these two systems interface with each other? Would using zlib slow down the loading process?  I've not had much experience with I/O in my career, so I'm not really sure where to start.
33056
I have a class that offers up a few events. That class is declared globally but not instanced upon that global declaration--it's instanced on an as-needed basis in the methods that need it.   Each time that class is needed in a method, it is instanced and event handlers are registered. Is it necessary to remove the event handlers explicitly before the method goes out of scope?   When the method goes out of scope, so goes the instance of the class. Does leaving event handlers registered with that instance that is going out of scope have a memory footprint implication? (I'm wondering if the event handler keeps the GC from seeing the class instance as no longer being referenced.)
84853
Comment on Duplicate Reference: Why would this be marked duplicate when it was asked years prior to the question referenced as a duplicate?  I also believe the question, detail, and response is much better than the referenced question.  I've been a C++ programmer for quite a while but I'm new to Java and new to Eclipse.  I want to use the  to visualize some data I'm working with.  This code is organized like this:  ./com ./com/touchgraph ./com/touchgraph/graphlayout ./com/touchgraph/graphlayout/Edge.java ./com/touchgraph/graphlayout/GLPanel.java ./com/touchgraph/graphlayout/graphelements ./com/touchgraph/graphlayout/graphelements/GESUtils.java ./com/touchgraph/graphlayout/graphelements/GraphEltSet.java ./com/touchgraph/graphlayout/graphelements/ImmutableGraphEltSet.java ./com/touchgraph/graphlayout/graphelements/Locality.java ./com/touchgraph/graphlayout/graphelements/TGForEachEdge.java ./com/touchgraph/graphlayout/graphelements/TGForEachNode.java ./com/touchgraph/graphlayout/graphelements/TGForEachNodePair.java ./com/touchgraph/graphlayout/graphelements/TGNodeQueue.java ./com/touchgraph/graphlayout/graphelements/VisibleLocality.java ./com/touchgraph/graphlayout/GraphLayoutApplet.java ./com/touchgraph/graphlayout/GraphListener.java ./com/touchgraph/graphlayout/interaction ./com/touchgraph/graphlayout/interaction/DragAddUI.java ./com/touchgraph/graphlayout/interaction/DragMultiselectUI.java ./com/touchgraph/graphlayout/interaction/DragNodeUI.java ./com/touchgraph/graphlayout/interaction/GLEditUI.java ./com/touchgraph/graphlayout/interaction/GLNavigateUI.java ./com/touchgraph/graphlayout/interaction/HVRotateDragUI.java ./com/touchgraph/graphlayout/interaction/HVScroll.java ./com/touchgraph/graphlayout/interaction/HyperScroll.java ./com/touchgraph/graphlayout/interaction/LocalityScroll.java ./com/touchgraph/graphlayout/interaction/RotateScroll.java ./com/touchgraph/graphlayout/interaction/TGAbstractClickUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractDragUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractMouseMotionUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractMousePausedUI.java ./com/touchgraph/graphlayout/interaction/TGSelfDeactivatingUI.java ./com/touchgraph/graphlayout/interaction/TGUIManager.java ./com/touchgraph/graphlayout/interaction/TGUserInterface.java ./com/touchgraph/graphlayout/interaction/ZoomScroll.java ./com/touchgraph/graphlayout/LocalityUtils.java ./com/touchgraph/graphlayout/Node.java ./com/touchgraph/graphlayout/TGAbstractLens.java ./com/touchgraph/graphlayout/TGException.java ./com/touchgraph/graphlayout/TGLayout.java ./com/touchgraph/graphlayout/TGLensSet.java ./com/touchgraph/graphlayout/TGPaintListener.java ./com/touchgraph/graphlayout/TGPanel.java ./com/touchgraph/graphlayout/TGPoint2D.java ./com/touchgraph/graphlayout/TGScrollPane.java ./TG-APACHE-LICENSE.txt ./TGGL ReleaseNotes.txt ./TGGraphLayout.html ./TGGraphLayout.jar   How do I add this project in Eclipse and get it compiling and running quickly?
94206
I have just started to learn Java and is curious is it any good practice in Java for good object decomposition? Let me describe a problem. In big software project it's always a big classes like 'core' or 'ui' that tends to have a lot of methods and are intended as a mediators between smaller classes. For example, if user clicks a button on some window, this window's class sends a message to 'ui' class. This 'ui' class catches this message and acts accordingly by doing something with application user interface ( via calling method of one of it's member objects ) or by posting message to application 'core' if it's something like 'exit application' or 'start network connection'.  Such objects is very hard to break apart since they are a mere mediators between a lots of small application objects. But having a classes in application with hundreds and thousands of methods is not very handy, event if such methods are trivial task delegation from one object to another. C# solves such problem by allowing to break class implementation into multiple source files: you can divide god object any way you choose, and it will work.  Any practices by dividing such objects in Java?
36061
Is it completely against the Java way to create struct like objects?  class SomeData1 {     public int x;     public int y; }   I can see a class with accessors and mutators being more Java like.  class SomeData2 {     int getX();     void setX(int x);      int getY();     void setY(int y);      private int x;     private int y; }   The class from the first example is notationally convenient.  // a function in a class public int f(SomeData1 d) {     return (3 * d.x) / d.y; }   This is not as convenient.  // a function in a class public int f(SomeData2 d) {     return (3 * d.getX()) / d.getY(); }
98762
In a game I'm working on, there's a class responsible for collision detection. It's method detectCollisions(List&lt;Entity&gt; entities) is called from the main gameloop.  The code to update the entities (i.e. where the entities 'act': update their positions, invoke AI, etc) is in a different class, in the method updateEntities(List&lt;Entity&gt; entities). Also called from the gameloop, after the collision detection.  When there's a collision between two entities, usually something needs to be done. For example, zero the velocity of both entities in the collision, or kill one of the entities.  It would be easy to have this code in the CollisionDetector class. E.g. in psuedocode:  for(Entity entityA in entities){     for(Entity entityB in entities){         if(collision(entityA, entityB)){             if(entityA instanceof Robot &amp;&amp; entityB instanceof Robot){                 entityA.setVelocity(0,0);                 entityB.setVelocity(0,0);             }             if(entityA instanceof Missile || entityB instanceof Missile){                 entityA.die();                 entityB.die();             }         }     } }   However, I'm not sure if updating the state of entities in response to collision should be the job of CollisionDetector. Maybe it should be the job of EntityUpdater, which runs after the collision detection in the gameloop.  Is it okay to have the code responding to collisions in the collision detection system? Or should the collision detection class only detect collisions, report them to some other class and have that class affect the state of the entities?
51358
How do you decide between passing arguments to a method versus simply declaring them as object instance variables that are visible to all of the object's methods? I prefer keeping instance variables in a list at the end of the Class, but this list gets longer as my program grows. I figure if a variable is passed often enough it should just be visible to all methods that need it, but then I wonder, &quot;if everything is public there will be no need for passing anything at all!&quot;
83916
I'm building a mod for Terraria that will add classes and their corresponding abilities to the game. You're a warrior? Push your ability key and you'll use your berserk ability.   I'm trying to make my player code as simple as possible. I'd like to set the player's in-game "class" by doing something like this at the top of the player class so the rest of the methods in it can access it later:  //Set class WarriorClass playerClass == new WarriorClass(playerReference, level)   Herein lies the first issue. I get an error at playerReference that says:  Error   CS0236  A field initializer cannot reference the non-static field, method, or property 'ModPlayer.playerReference'  MyMod   Ok, so I looked that up and set the initialization in the WarriorClass instead:  public Player playerReference = new Player();   And I have this now in my player code:  //Set class      WarriorClass playerClass = new WarriorClass(level);   Here's the beauty of it. In the gamepad input method within my player code all I ever have to do is:      //On key presses     public override void ProcessTriggers(TriggersSet triggersSet)     {         if (MyMod.ability1Key.JustPressed)         {              playerClass.UseAbility(MyMod.ability1Key);         }   Now that the ability1 key was pressed, let the WarriorClass handle what to do:      public void UseAbility(ModHotKey key)     {             //Ability 1             if (key.JustPressed == MyMod.ability1Key)             {                 //Start berserking                 if (player.HasBuff(ModContent.BuffType&lt;BerserkBuff&gt;()) == false )                 {                     //Lose 10% of your life                     lifeLost = player.statLifeMax2 / 10;                     player.statLife = player.statLife - (int)lifeLost;                      //Berserk and add damage over in the Buff code                     player.AddBuff(ModContent.BuffType&lt;BerserkBuff&gt;(), 600, false);                 }   This is all great!!! I can add any amount of classes I want and this player code never changes. Except If I want to add if/then logic to select a class in say, Update() then it breaks the following reference in my gamepad input code:  playerClass.UseAbility(MyMod.ability1Key);   Of course it won't have a reference unless I hard code it at the top of the player file, but I don't know what class a player will be until they pick one.  Am I doing this fundamentally in a bad way or am I missing something else in terms of OO programming? I don't want to have to initialize every class for the character at the top of the file like this:  WarriorClass warriorClass = new WarriorClass(level); ArcherClass archerClass = new ArcherClass(level); ...   ... just to do this in the gamepad input method:  if (classChoice == "Warrior") {      warriorClass.UseAbility(MyMod.ability1Key); } else if (classChoice == "Archer") {      archerClass.UseAbility(MyMod.ability1Key); }
45010
I am developing my first 2D game in Unity and I have come across what seems an important question.  How do I handle data between scenes?  There seems to be different answers to this:   Someone mention using , while other people told me this should be used to store other things like screen brightness and so on. Someone told me that the best way was to make sure to write everything into a savegame everytime that I changed scenes, and to make sure that when the new scene loads, get the info from the savegame again. This seemed to me wasteful in performance. Was I wrong? The other solution, which is the one I have implemented so far is to have a global game object that isn't destroyed between scenes, handling all the data between scenes. So when the game starts, I load a Start Scene where this object is loaded. After this ends, it loads the first real game scene, usually a main menu.   This is my implementation:  using UnityEngine; using UnityEngine.UI; using System.Collections;  public class GameController : MonoBehaviour {      // Make global     public static GameController Instance {         get;         set;     }      void Awake () {         DontDestroyOnLoad (transform.gameObject);         Instance = this;     }      void Start() {         //Load first game scene (probably main menu)         Application.LoadLevel(2);     }      // Data persisted between scenes     public int exp = 0;     public int armor = 0;     public int weapon = 0;     //... }   This object can be handled on my other classes like this:  private GameController gameController = GameController.Instance;   While this has worked so far, it presents me with one big problem: If I want to load directly a scene, let's say for instance the final level of the game, I can't load it directly, since that scene does not contain this global game object.  Am I handling this problem the wrong way? Are there better practices for this kind of challenge? I would love to hear your opinions, thoughts and suggestions on this issue.  Thanks
56376
I'm trying to get my head around mutable vs immutable objects. Using mutable objects gets a lot of bad press (e.g. returning an array of strings from a method) but I'm having trouble understanding what the negative impacts are of this. What are the best practices around using mutable objects? Should you avoid them whenever possible?
45793
I want to build a game with a concept similar to , where the game map is overlaid on a real one.  Where can I find map data for an app like that? How (generally) do I integrate my own game objects into that map? Game objects need to move in real time, so having them as static markers on the map isn't sufficient.  I thought I could use Google Maps but as far as I can tell it would be impossible to create my own graphical style (like Ingress has done) with the official API provided by Google.
10510
In my addon panel, how can I have an object selection box?  And what data type would I use to store the the selected object?  It should look like this:
100133
Please don't mark this as a duplicate of my previous question which was asked anonymously. this is a reattempt because i cannot edit the first attempt.  What I have so far is:  - randomly generated tile set with items on SOME tiles - one creature spawner that spawns up to 5 creatures which can be controlled by the player - the ability for creatures to pick up items and bring them back to the spawn and store them for later use  What I am noticing is when i launch the game, it doesnt always show all the sprites. Sometimes the spawner is missing, or the creatures, or the GUI. ANd when things DO appear, if i tell the creatures to pick up anything, other items on the ground randomly appear and disappear. even the spawn sometimes disappears! what I do notice is that when i have multiple creatures, some will disappear when crossing invisible lines but not all of them. i forced two creatures to go east at the same speed and time, and one vanished and the other didnt.  If you have any ideas as to what might be causing this, please let me know. if you have any questions, i'll try to edit to appease you.  thanks for reading!  I have my draw method like this:  GraphicsDevice.Clear(Color.CornflowerBlue);  // TODO: Add your drawing code here  spriteBatch.Begin(SpriteSortMode.BackToFront,           null, null, null, null, null,           camera.GetTransformation());            worldEntity.Draw(spriteBatch);  guiManager.DrawGUI(spriteBatch);  spriteBatch.End();  base.Draw(gameTime);   for the world entity...  its draw method systematically goes through each tile in the world and calls its draw method. the tile draws itself using  Vector2 topLeftOfSprite = new Vector2(this.X, this.Y); Color tintColor = Color.White; spriteBatch.Draw(tileTexture, topLeftOfSprite, tintColor);   and then proceeds to call the draw method of any items on it.  creatures and items have very similar draw methods.  the gui also draws itself in a similar fashion.  what i DO notice is that ive NEVER seen ground tiles vanish, only the items on them or creatures in the world. Could it be their Z isn't set appropriately?
37688
More often than not I need to elaborate my question put up on Stack Overflow with a custom sketch, UML class diagram, flow chart.    It is in these times I have to open up a custom paint software, factor out some diagrams, export it as an image, attach it to Stack Overflow. I wouldn't know how complicated it is to invest in having such a sketching or drawing tool integrated, It could even be a basic pen stripped off all the advanced features leaving it a bare minimum.  Such a tool if incorporated into the Stack Overflow "ask question" UI would be certainly helpful.  As of Today this Question has been visited around 170 times and 7 answers, This was meant to be the voice of Stack Overflow users. Would you need a Drawing Tool for you on the Stack Overflow site, would it help you to express you questions and answers better? Sadly, only 2, or 3 answers are in the context of the question. The bounty was meant to be a bait and even that ends tomorrow. Hope you'll get the will and the zest to comment on this question today and in the future .