Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
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   
Pages: [1]
  ignore  |  Print  
  my game i'm making is taking up all my RAM.  (Read 1871 times)
0 Members and 2 Guests are viewing this topic.
Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Posted 2014-08-04 02:07:20 »

so i'm making a game and all i have done is the texture of the main menu,but i ran into a problem.when ever i run the game and i wait a couple if seconds and then my RAM goes all the way up to 99% use in around a minute.i can't continue the game unless i fix this.i'm using Java (of course),eclipse,and libGDX.Does anyone know how i can fix this?
Offline Slyth2727
« Reply #1 - Posted 2014-08-04 02:14:37 »

Look for a loop somewhere that's creating a bunch of objects. You may accidentally not be exiting a loop, therefore it's making a bunch of things. Also, you might have something in an update method that should be in an initialization method.

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Reply #2 - Posted 2014-08-04 03:02:21 »

Look for a loop somewhere that's creating a bunch of objects. You may accidentally not be exiting a loop, therefore it's making a bunch of things. Also, you might have something in an update method that should be in an initialization method.
should i add my code so u can see if there is anything wrong?I don't think there is a loop but it can be a bunch of things...I think this is a update method-
1  
camera.update();

if it is how would i change it?Also how could i find a loop...Also sorry i'm kind of newbie at this...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longarmx
« Reply #3 - Posted 2014-08-04 03:16:35 »

Do you keep loading textures or creating new objects in the render method?

Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Reply #4 - Posted 2014-08-04 03:19:13 »

Do you keep loading textures or creating new objects in the render method?
is this what your talking about?-
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
@Override
   public void render(float delta) {
      Gdx.gl.glClearColor(1F,1F,1F,1F);  
      Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
     
      camera.update(true);

      batch.setProjectionMatrix(camera.combined);{
         
         Texture texture_back;
         
         texture_back = new Texture(Gdx.files.internal("menu/back.png"));
         
      batch.begin();
      batch.draw(texture_back, 0, 0);
      batch.end();
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #5 - Posted 2014-08-04 03:21:33 »

Yes, that texture_back object is being created every frame, which you do not want to do. Keep the texture object in global space and then create the texture in the create method. I also recommend you learn the basics of LibGDX and how rendering works. Also learn about objects in Java and how they are created.

Offline Longarmx
« Reply #6 - Posted 2014-08-04 03:24:35 »

is this what your talking about?-
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
@Override
   public void render(float delta) {
      Gdx.gl.glClearColor(1F,1F,1F,1F);  
      Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
     
      camera.update(true);

      batch.setProjectionMatrix(camera.combined);{
         
         Texture texture_back;
         
        texture_back = new Texture(Gdx.files.internal("menu/back.png"));
         
      batch.begin();
      batch.draw(texture_back, 0, 0);
      batch.end();


Yep. I've highlighted the problem line. To fix this, put the highlighted line in the
create()
method, and make the
texture_back
a global variable by putting it outside of any methods. (Right above the create method is a good place)

Edit: What opiop said

Offline Longarmx
« Reply #7 - Posted 2014-08-04 03:29:20 »

1  
2  
3  
4  
5  
6  
Texture texture_back;

@Override
public void create() {
     texture_back = new Texture(Gdx.files.internal("menu/back.png"));
}

Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Reply #8 - Posted 2014-08-04 03:33:36 »

1  
2  
3  
4  
5  
6  
Texture texture_back;

@Override
public void create() {
     texture_back = new Texture(Gdx.files.internal("menu/back.png"));
}

it created a error where the texture_back is-
1  
2  
3  
   batch.begin();
      batch.draw(texture_back, 0, 0);
      batch.end();
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #9 - Posted 2014-08-04 03:34:15 »

What error did it create? A nullpointer?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longarmx
« Reply #10 - Posted 2014-08-04 03:34:47 »

You have a lonely opening brace after
batch.setProjectionMatrix(camera.combined);
 Smiley

Edit: I'm not sure if this is causing the problem, but you should post the stack trace so we can make sure.

Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Reply #11 - Posted 2014-08-04 03:44:23 »

You have a lonely opening brace after
batch.setProjectionMatrix(camera.combined);
 Smiley

Edit: I'm not sure if this is causing the problem, but you should post the stack trace so we can make sure.
here's the whole method with the error at texture_back-
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
@Override
   public void render(float delta) {
      Gdx.gl.glClearColor(1F,1F,1F,1F);  
      Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
     
      camera.update(true);

      batch.setProjectionMatrix(camera.combined);{
         
      batch.begin();
      batch.draw(texture_back, 0, 0);
      batch.end();
   
      }
     
   }

it says it can't be resolved to a variable.

edit-the create method is also in the game class not the Main or the GameScreen class
Offline Longarmx
« Reply #12 - Posted 2014-08-04 03:51:52 »

Oh whoops! Are you extending the screen class? You would then put the code in the init method in the same class as this render method.

Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #13 - Posted 2014-08-04 03:53:01 »

Or you could through the code into the constructor for the class.

Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Reply #14 - Posted 2014-08-04 03:55:31 »

Oh whoops! Are you extending the screen class? You would then put the code in the init method in the same class as this render method.
should i just show u all of my classes done which is only 3.the game class is extending but the GameScreen class is not.
Offline Longarmx
« Reply #15 - Posted 2014-08-04 03:58:23 »

Just put the code in the constructor of this class like opiop suggested.

Offline BurntPizza
« Reply #16 - Posted 2014-08-04 03:58:45 »

I really can't stress this enough: don't start programming straight off with making games and third party frameworks. I know game development is often appealing, but it's one of the more involved divisions of programming, involving aspects from all over the place.
Sure, we can help you with this one issue, but you will only keep having problems if you don't know the fundamentals. You'll only frustrate yourself as it's like trying to do algebra without knowing about the concept of arithmetic.

I recommend starting out with something like Code Academy, and maybe picking up an actual book or two. I've yet to find internet tutorials that can hold a candle to a good book. A good book will walk you through the basics, then have you write simple programs, bringing up your capabilities at the same pace as your knowledge, unlike diving off the deep end of game dev without knowing how to swim.
Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Reply #17 - Posted 2014-08-04 04:03:53 »

I really can't stress this enough: don't start programming straight off with making games and third party frameworks. I know game development is often appealing, but it's one of the more involved divisions of programming, involving aspects from all over the place.
Sure, we can help you with this one issue, but you will only keep having problems if you don't know the fundamentals. You'll only frustrate yourself as it's like trying to do algebra without knowing about the concept of arithmetic.

I recommend starting out with something like Code Academy, and maybe picking up an actual book or two. I've yet to find internet tutorials that can hold a candle to a good book. A good book will walk you through the basics, then have you write simple programs, bringing up your capabilities at the same pace as your knowledge, unlike diving off the deep end of game dev without knowing how to swim.
i'm sorry..I'm only 13 and all i really looked at where videos that showed me very basic stuff...I've started learning this about 2 weeks ago and i just thought it would be cool to know stuff like this.I might try the Code Academy considering that it is free.
Offline BurntPizza
« Reply #18 - Posted 2014-08-04 04:08:47 »

i'm sorry..I'm only 13 and all i really looked at where videos that showed me very basic stuff...I've started learning this about 2 weeks ago and i just thought it would be cool to know stuff like this.

Don't be sorry. It's cool you think programming is cool, because it is. But to become good at it you have to ease into it, and start with the basics. Trust me when I say game programming isn't basic at all, at least at even this level. It terms of games, you should start out with a text-based game that runs in the console. If you can do that, then you'll have learned quite a bit already. Even more basic than that would be a calculator program, type in numbers, tell it what you want to compute, and it spits out an answer. That's a sample exercise from one of the books I started with.
Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Reply #19 - Posted 2014-08-04 04:10:03 »

Just put the code in the constructor of this class like opiop suggested.
so basically add it to its own class as a object?
Offline CogWheelz
« Reply #20 - Posted 2014-08-04 04:12:57 »

BurntPizza is right. I made the same mistake at the same age a year ago. It took me months to realize that I needed to learn more Java. http://www.tutorialspoint.com/java/ This is a good place to start as well as a book.
Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Reply #21 - Posted 2014-08-04 04:14:40 »

i'm sorry..I'm only 13 and all i really looked at where videos that showed me very basic stuff...I've started learning this about 2 weeks ago and i just thought it would be cool to know stuff like this.

Don't be sorry. It's cool you think programming is cool, because it is. But to become good at it you have to ease into it, and start with the basics. Trust me when I say game programming isn't basic at all, at least at even this level. It terms of games, you should start out with a text-based game that runs in the console. If you can do that, then you'll have learned quite a bit already. Even more basic than that would be a calculator program, type in numbers, tell it what you want to compute, and it spits out an answer. That's a sample exercise from one of the books I started with.
I have learned a little about variables,operators,casting,user input,objects,and if,else,and,or.Most of the time i'm learning as i go.
Offline Longor1996
« Reply #22 - Posted 2014-08-04 09:11:44 »

I have learned a little about variables,operators,casting,user input,objects,and if,else,and,or.Most of the time i'm learning as i go.

Don't learn the basics of Java 'as you go' by trying to make games.
This will bite you in the ass later on, and it will bite (very) hard.


Learn the basics of Java by making things like a Calculator, or a Text-Adventure.
Then go and make 2D games.

Have a nice day.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline ags1

JGO Ninja


Medals: 62
Projects: 3
Exp: 5 years


Make code not war!


« Reply #23 - Posted 2014-08-04 10:39:36 »

At least look up the Java tutorials by Oracle and follow some of them.

http://docs.oracle.com/javase/tutorial/getStarted/index.html

Also (maybe I am showing my advanced age here) I can't imagine anything more useless that watching coding videos or live code streaming. You need to be able to work through things at your own pace, which means videos are counterproductive.

Offline Cero
« Reply #24 - Posted 2014-08-04 14:32:04 »

I have learned a little about variables,operators,casting,user input,objects,and if,else,and,or.Most of the time i'm learning as i go.

Don't learn the basics of Java 'as you go' by trying to make games.
This will bite you in the ass later on, and it will bite (very) hard.


Learn the basics of Java by making things like a Calculator, or a Text-Adventure.
Then go and make 2D games.

Have a nice day.

- Longor1996

Gotta disagree a little here.
You learn way better when you actually want something to work and therefore are forced to learn things to make it work.
It's waaay better then simple studying or doing exercises that are just out of context and everything

However it means that the game you are creating while learning will not be a good game but simply your laboratory if you will... if you accept that, its a very good choice actually.

If you really lack a lot of basics... can be frustrating of course

Offline SwordsMiner

JGO Coder


Medals: 3
Projects: 2
Exp: 1 year


The one and only.


« Reply #25 - Posted 2014-08-04 20:40:14 »

I have learned a little about variables,operators,casting,user input,objects,and if,else,and,or.Most of the time i'm learning as i go.

Don't learn the basics of Java 'as you go' by trying to make games.
This will bite you in the ass later on, and it will bite (very) hard.


Learn the basics of Java by making things like a Calculator, or a Text-Adventure.
Then go and make 2D games.

Have a nice day.

- Longor1996

To add on to this, the mistake that people often make is what Longor says, but the outcome is coming to the point where you look back at your unbelievably horrible code and you end up having to recode it all over and over again.

If I made you laugh, helped you at all, or did something cool, I only ask that you smash that appreciate button with your nose.
Offline DeathByFire223

Senior Newbie


Exp: 1 month or less



« Reply #26 - Posted 2014-08-04 21:33:59 »

Or you could through the code into the constructor for the class.
thank u i finally fixed it!also thanks longarmx as well!what i did was i put the code above the render method in the constructor!
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

Grunnt (17 views)
2014-09-23 14:38:19

radar3301 (14 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (29 views)
2014-09-20 20:14:06

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

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

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

TehJavaDev (105 views)
2014-09-10 06:39:09
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!