Basically I am creating a simply game, I want circles to appear but they can not overlap each other when they are printed on the screen. The objects are created and then put into an arraylist and when ever another is created it needs to check its coordinates with all the others already in the arraylist to make sure its not the same. The method to check is called isCollidingWith and there is a setPosition method that actually sets the position. This is what I have.  This is how the object is created, I can't even get one to be created, once I get it working I would create more of these objects, hence the whole point of this.      Circle circle = new Circle(rng,circles);     circles.add(circle);   This is the constructor for the object takes in a random number and and arraylist of circles. It starts with a while loop and sets a position for this circle it then goes into a for loop and checks if it is colliding with and of the other ones, if it is, it breaks and goes back to the top of the while loop and sets a different positions and then repeats checking if it is colliding with any of the other ones already in the arraylist.      public Planet(Random rng, ArrayList&lt;Circle&gt; circles){          boolean key = true;         while(key){          this.graphic.setPosition(rng.nextFloat()*GameEngine.getWidth(),rng.nextFloat()*GameEngine.getHeight());          for(int i = 0; i&lt;circles.size();i++){             if(this.graphic.isCollidingWith(circles.get(i).graphic)){                 key = true;                 break;             }             else key = false;          }          }       }   The problem is I keep getting a NullPointerException at the line in the constructor where it says this.graphic.setPosition. But I am guessing it has to do with the arraylist, because eclipse usually isn't that accurate with error positioning. If anyone could tell me what looks to be wrong here that would be great.
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
99218
I currently have something like:  float deltaX = point0.getX() - point1.getX(); float deltaY = point0.getY() - point1.getY();   And every 0.01 seconds I refresh my objects position like this:  object.setPosition(object.getX()-deltaX/100,object.getY()-deltaY/100);   So this moves my object from point0 to point1 in 1 second. What I need is having the 2 points, to be able to move the object from point0 ,facing(in the direction of) point1 with a constant speed. Thus, when I have a point closer to my initial point the object will move towards it with the same speed it does if I would have a farther point. Any suggestions are appreciated. Thanks.
4920
Given an aggregation of class instances which refer to each other in a complex, circular, fashion: is it possible that the garbage collector may not be able to free these objects?  I vaguely recall this being an issue in the JVM in the past, but I thought this was resolved years ago.  yet, some investigation in jhat has revealed a circular reference being the reason for a memory leak that I am now faced with.  Note: I have always been under the impression that the JVM was capable of resolving circular references and freeing such "islands of garbage" from memory.  However, I am posing this question just to see if anyone has found any exceptions.
89675
I think there is a way to do an inside radius, and an outside radius, but how? I want to have a spawnpoint, where @a[r=30] is in gamemode a, and everyone outside is gamemode s. How would I write this?
101123
Right now, when I spawn a shootable object, it goes like this:    Because I just set it's angle to this:  float aimAngle = (float) Math.atan2(velocity.y, velocity.x); bullet.setBodyAngle(aimAngle);   I want it to be like this:    I think I should use angular velocity or torque, but I have no idea how. I can't just set it's angle like in previous code every frame, because it makes physics collisions glitch.
92666
Seem to have exhausted google looking for an answer to a VERY bullet simple code that should work.  void onCollisionEnter(Collision col) {     print ("hit " + col.gameObject.name);     Destroy (gameObject);     }   Bullet object has the above script, SphereCollider (radius a lot bigger than object), RigidBody, not a trigger, not kinematic, is travelling slow. All checked during runtime.  When it hits a wall (Box collider), it just bounces off but no collisionEnter code is ran.  Debug console bubble is on.
57681
I am developing a small 2D game engine. The characters have a paint method which currently does the following:   Calculate the new position of the character as per its speed, etc. Update the collision grid cell ** Draw the character at the new position   ** I have created a collision grid to reduce the number of intersection checks  Now the basic algorithm which I have thought for detecting collision is:   For Each Character     Check intersection with characters in surrounding 8 cells   I can simply place this code in the paint method. But here is the problem I anticipate.  Suppose two characters A and B lie in adjacent cells in the collision grid. Now as per the above algorithm in the iteration of character A it will detect that it has collided with B. In the iteration for character B it will detect that it has collided with A.  But I have an idea that when A detects that it has collided with B, it should inform B that it has collided with A. This would save lot of comparisons when there are more than 2 actors colliding. But I am not sure how to handle this. I think instead of every character checking for its collision, I should check for the collision inside the game loop.   Would this approach be correct? How have you handled this kind of problem? I thought of the collision grid thing myself. Are there any alternatives to collision grid logic?
108435
Andrew Stacey  that the Rosetta Code entry  doesn't have a TikZ entry yet.  Is there a way to draw a "properly" shaded sphere using TikZ? The ball shading would seem an obvious choice, but it uses a circular highlight, which is not what it would look like in reality. So: is there a way to make a sphere that would resemble a white, matte (i.e. non-shiny) ball that is illuminated by a single white light source?  This would mainly require getting a non-circular, correctly oriented highlight, I believe. Both Yori's and Altermundus' answer already do a great job at using a "softer" highlight, which looks more believable, but Altermundus' highlight is still circular, and while Yoris' is elliptic, it's not oriented correctly, I think.  Compare a circle with the ball shading to the :    \documentclass{article}  \usepackage{tikz}  \begin{document}  \begin{minipage}{2.5cm}\centering \scriptsize That's not a sphere.  \tikz{     \fill [black] (-1,-1) rectangle (1,1);     \shade [ball color=white] (0,0) circle [radius=1cm]; } \end{minipage}% % \begin{minipage}{2.5cm}\centering \scriptsize \emph{That's} a sphere.  \includegraphics[width=2cm]{Sphere-perl6.png} \end{minipage} \end{document}
1559
Consider the task of generating random points uniformly distributed within a circle of a given radius $r$ that is centered at the origin. Assume that we are given a random number generator $R$ that generates a floating point number uniformly distributed in the range $[0, 1)$.  Consider the following procedure:   Generate a random point $p = (x, y)$ within a square of side $2r$ centered at the origin. This can be easily achieved by:  a. Using the random number generator $R$ to generate two random numbers $x$ and $y$, where $x, y \in [0, 1)$, and then transforming $x$ and $y$ to the range $[0, r)$ (by multiplying each by $r$).  b. Flipping a fair coin to decide whether to reflect $p$ around the $x$-axis.  c. Flipping another fair coin to decide whether to reflect $p$ around the $y$-axis. Now, if $p$ happens to fall outside the given circle, discard $p$ and generate another point. Repeat the procedure until $p$ falls within the circle.   Is the previous procedure correct? That is, are the random points generated by it uniformly distributed within the given circle? How can one formally [dis]prove it?    Background Info  The task was actually given in . If you're interested, you can  in which I've implemented the procedure described above. I would like to know whether the procedure is mathematically correct or not, but I couldn't figure out how to formally [dis]prove it.  Note that the actual task was to generate random points uniformly distributed within a circle of a given radius and position, but I intentionally left that out in the question because the generated points can be easily translated to their correct positions relative to the given center.
52439
I have two objects (target and player), both have Position (Vector3) and Rotation (Quaternion).  I want the target to rotate and be facing right at the player.  The target, when it shoots something should shoot right at the player.    I've seen plenty of examples of slerping to the player, but I don't want incremental rotation, well, I suppose that would be ok as long as I can make the slerp be 100%, and as long as it actually worked.  FYI - Im able to use the position and rotation to do plenty of other things and it all works great except this last piece I cant figure out.  Code samples run in the Target's class, Position = the targets position, Avatar = the player.  EDIT  Im now using Maik's c# code he has provided and it works great!
84342
I have a JFrame. This JFrame contains a JButton. I click the JButton and 10 JTextFields are created.  the problem: I cannot see them until "I force a repaint()" by resizing the window. Only then do I see the JTextFields created.  CODE:  JPanel points = new JPanel();  //Creating the JTextFields: for (int i=0; i&lt;10; i++) {     JTextField textField = new JTextField();     points.add(textField); }  repaint(); this.repaint(); super.repaint(); points.repaint();     THANK YOU - after the for loop, I just called points.validate() and it worked...
100547
I'm trying to get the bounds of an object and put a box around it.  Sounds simple right? I just encapsulate all the bounds together and use its center and size to do so.  But the problem is one corner of the box is always at the center of the scene, like a part of the object is there, unless the center of the scene is in the bounds.  This is when object is at the center   This is when it isn't  This is the code i'm using:      public static Bounds Calculate(Transform TheObject)     {         Renderer renderer = TheObject.GetComponent&lt;Renderer&gt;();         Bounds combinedBounds = new Bounds();         if (renderer != null)             combinedBounds = renderer.bounds;         var renderers = TheObject.GetComponentsInChildren&lt;Renderer&gt;();         foreach (Renderer render in renderers)         {             if (render != renderer) combinedBounds.Encapsulate(render.bounds);         }         return combinedBounds;     }
48565
I found out about this using a debug renderer. When the game starts, everything is in order. But when a collision happens, the sprite's rotation is way larger than its body. The sprite and body match when the body is completely horizontal.    The sprite's rotation origin seems far distant from where it should be. Here's my code:  Sprite sprite = data.sprite; position = body.getPosition(); sprite.setPosition(     position.x - sprite.getWidth()  / 2,     position.y - sprite.getHeight() / 2 ); sprite.setOrigin(position.x, position.y); sprite.setRotation(MathUtils.radiansToDegrees * body.getAngle());   As you can see, I am even trying to set center of its rotation with setOrigin without success. How can I fix this?
49096
I'm working with a Minecraft model, and am using hand places cubes as extrusions for the hair of the character, as I am unsure of how to extrude pixel sized "blocks" from the mesh. The problem I have arises with a tiny bit of overlap with some of the cubes, causing a weird look. Is there a way to fix this overlap without having to go back and hand scale/rearrange the cubes, or an easier way to achieve this extrusion? The cube's aren't perfectly aligned, as I did it all by hand. Is there possibly an easier way to align them?
122744
I am trying to make a circle with dash but there's a black line that wont go away.  How do I fix this? I have looked through the appearances tab. I have also tried deleting that object then redoing it but, nothing has worked. It is one single image that has three strokes on it. It might just be a glitch in my program.
69920
TL;DR  How to take a shape or Image Texture and multiply it with random Location, Rotation and Scale along object:    Background  I have created my first procedural shape on my own from this function: $(x^2 + y^2 - 1)^3 - x^2y^3 = 0$   (big yay for math idiot)   Here is the result:    And I want to do something useful with it.  Research  I've tried to find something similar over the web (this is trending right now) and I'm surprised that this question wasn't asked before or I'm looking with wrong terms. I've tried random pattern, duplicating texture, populating image, random tiles, custom tiles and such. There is a lot about tiling textures but each and every Q&amp;A I've stumbled upon are about non overlapping ones. For example:            Tryout:  The only way I can think of this is to duplicate shape as a group and manually change values in Mapping Nodes:    As you can see this is... Well. Bad.  I've tried messing with Modulo, mixing Noise between vectors, using custom node groups for LocRotScale (thanks Gandalf) but results was none, thus nothing even to show.  Question  I want to populate this shape (or any other) along the object with random Location, Rotation and Scale - with control over its number/density and maybe variation strength.  Edit: I'm not looking for alternative methods of creating this setup such as Particles, Image Textures generated in 3rd party software, OSL shaders (CPU only) and such. My intention is to use this in procedural texture generation in Cycles with GPU support.  Blend file  Nothing really needed for this question but here - have this heart from me :)
34676
I am trying to do a Minecraft-like game (like every one have already tried I guess) and i went across the problem i expected: lag with world Generation. I did lot of searching but i can  I tried to combine them into a bigger mesh, which work, but not i can destroy a single block. So how can I place/destroy chunked (mesh combined) block? If i cant, can someone clearly explain me a solution (i am not fluent in english nor with programming expressions, i can code tho) and how to do it (with a script example if possible :) ) ? Thanks in advance !  I generated my world using 2D perlin noise. Once i have the blocks, i split them into 16x16x100 chunk meshes.  Before Making chunks, i first tried to combine all of them into one block (using the unity manual), but the result is only one cube placed at 0,0,0. Where are all the other cubes ?  using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public class ThisWorldGen : MonoBehaviour {  public GameObject blockPrefab; public GameObject grass; public GameObject dirt; public GameObject rock; private string[] blockTag;  private GameObject stockin;   public int amp; public int freq; private Vector3 mypos; [SerializeField] private Material material; private Vector3 blockLocations;  public List&lt;MeshFilter&gt; meshes = new List&lt;MeshFilter&gt;();  void Start() {     Generate(); }  void Generate() {     amp = Random.Range(0,100);     freq = Random.Range(30,100);     mypos = this.transform.position;     int cols = 100;     int rows = 100;     float startTime = Time.realtimeSinceStartup;         #region Create Mesh Data     MeshFilter blockMeshes = Instantiate(blockPrefab, Vector3.zero, Quaternion.identity).GetComponent&lt;MeshFilter&gt;();      for(int x = 0; x &lt; cols;x++)     {         for(int z = 0; z &lt; rows;z++)         {              float y = Mathf.PerlinNoise ((mypos.x + x) / freq,(mypos.z + z)/freq) * amp;             y = Mathf.Floor(y);             for(float hy = y; y &gt; 0.0F; y -= 1.0F)             {                            blockMeshes.transform.position = new Vector3(mypos.x + x,y,mypos.z +z);//move the unit cube to the intended position                 meshes.Add(blockMeshes);                     }         }     }     int i = 0;     MeshFilter[] listMeshes = new MeshFilter[meshes.Count];     foreach(MeshFilter cubesToAdd in meshes)     {                            listMeshes[i] = cubesToAdd;         i++;     }     CombineInstance[] combine = new CombineInstance[listMeshes.Length];     int w = 0;     while(w &lt; listMeshes.Length)     {            combine[w].mesh = listMeshes[w].sharedMesh;         combine[w].transform = listMeshes[w].transform.localToWorldMatrix;         listMeshes[w].gameObject.SetActive(false);         w++;     }     Debug.Log (combine.Length);     transform.GetComponent&lt;MeshFilter&gt;().mesh = new Mesh();     transform.GetComponent&lt;MeshFilter&gt;().mesh.CombineMeshes(combine);     transform.gameObject.SetActive(true);     #endregion     Debug.Log("Loaded in " + (Time.realtimeSinceStartup - startTime) + " Seconds."); } }   (the world was generating randomly and perfectly before trying to merge the meshes)