Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGdx, objects dont move  (Read 2229 times)
0 Members and 1 Guest are viewing this topic.
Offline vastrolorde

Junior Devvie





« Posted 2014-07-04 11:32:06 »

Im creating 32 object with each method call, and they should move in different directions, but what is happening is that they spawn, but wont move. What might be the issue here?


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  
class that handles all the objects in the world
public void update(float delta){
      runTime += delta;
       player.update(delta);
       for(Enemy e: enemy){
          e.update(delta);
       }
       
       for(CircleBullet b: bullets){
          b.update(delta);
       }
       if(runTime > 0.25){
          enemy.add(new Enemy1(0,GameConstants.GAMEHEIGHT-12,12,12, new Vector2(90,-200),new Vector2(0,150), 1));
          enemy.add(new Enemy1(GameConstants.GAMEWIDTH-12,GameConstants.GAMEHEIGHT-12,12,12,
                new Vector2(-90,-200),new Vector2(0,150), -1));
          runTime = 0;
       }
   }

The class that creates the 32 bullets.
public class shot {
   private Vector2 position;
   private ArrayList<CircleBullet> bullets = new ArrayList<CircleBullet>();
   private Vector2 velocity;
   
   public shot(float x, float y){
      velocity = new Vector2(0,5);
      position = new Vector2(x,y);
      for(int i = 0; i<32; i++){
         velocity.setAngle(i*11.25f);
         GameWorld.bullets.add(new CircleBullet(position, velocity.x, velocity.y));
      }
   }
   
   public void update(float delta){
      for(CircleBullet b: bullets){
         b.update(delta);
      }
   }
   
   public float getX(){
      return position.x;
   }
   
   public float getY(){
      return position.y;
   }
   
   public ArrayList<CircleBullet> getBullets(){
      return bullets;
   }
}

CircleBullet class
public class CircleBullet {
   private Vector2 position;
   private Vector2 velocity;
   
   public CircleBullet(Vector2 position, float vx, float vy){
      this.position = position;
      this.velocity = new Vector2(vx, vy);
   }
   
   public void update(float delta){
      position.add(velocity.cpy().scl(delta));

   }
   
   public float getX(){
      return position.x;
   }
   
   public float getY(){
      return position.y;
   }
}
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 270
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #1 - Posted 2014-07-04 13:54:28 »

Can you post an MCVE instead of an incomplete code snippet? Not your whole project, just enough for us to be able to run the code and see the problem.

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline vastrolorde

Junior Devvie





« Reply #2 - Posted 2014-07-04 16:48:15 »

So this is the minimal code needed. http://pastebin.java-gaming.org/8e3de6e040a1a if you want to move the character around then most of the stuff remains, just the touchpad needs to be re-inserted(remove comment marks, and in player class add touchpad to constructor). 

This is cut version of the code. And i used libGdx to create this.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CopyableCougar4
« Reply #3 - Posted 2014-07-04 18:01:07 »

Hi

Do you ever call the method update() for your world? I didn't see anything in the code sample but I may have missed something.

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline vastrolorde

Junior Devvie





« Reply #4 - Posted 2014-07-04 18:30:42 »

Its in the screen class. Screen class serves basicly as the game loop
Offline vastrolorde

Junior Devvie





« Reply #5 - Posted 2014-07-05 07:33:07 »

I fount out that the problem lies within the shot class.
When i create CircleBullet separately then it works fine, but when i use the shot class, it doesent move anymore.
What might cause this problem? This Class seems ok to me.

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  
public class shot {
   private Vector2 position;
   private ArrayList<CircleBullet> bullets = new ArrayList<CircleBullet>();
   private Vector2 velocity;
   
   public shot(float x, float y){
      velocity = new Vector2(0,50);
      position = new Vector2(x,y);
      for(int i = 0; i<32; i++){
         velocity.rotate(i*11.25f);
         bullets.add(new CircleBullet(position, velocity.x, velocity.y));
      }
   }
   
   public void update(float delta){
      for(CircleBullet b: bullets){
         b.update(delta);
      }
   }
   
   public float getX(){
      return position.x;
   }
   
   public float getY(){
      return position.y;
   }
   
   public ArrayList<CircleBullet> getBullets(){
      return bullets;
   }
}
Offline vastrolorde

Junior Devvie





« Reply #6 - Posted 2014-07-05 17:55:40 »

Fixed it. Somewhere along the line of getting the info to update bullet positions, update method wasnt called.
Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (110 views)
2017-09-30 02:57:34

theagentd (144 views)
2017-09-26 18:23:31

cybrmynd (245 views)
2017-08-02 12:28:51

cybrmynd (241 views)
2017-08-02 12:19:43

cybrmynd (240 views)
2017-08-02 12:18:09

Sralse (254 views)
2017-07-25 17:13:48

Archive (872 views)
2017-04-27 17:45:51

buddyBro (1016 views)
2017-04-05 03:38:00

CopyableCougar4 (1573 views)
2017-03-24 15:39:42

theagentd (1373 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!