i have a terrarian style terrain engine but it runs extremly slow. my engine only renders whats on screen. there are individual blocks being spawn. so my question is, how can i get my frame rate as high as in terraria? btw my engine is 2d
- thanks
i have a terrarian style terrain engine but it runs extremly slow. my engine only renders whats on screen. there are individual blocks being spawn. so my question is, how can i get my frame rate as high as in terraria? btw my engine is 2d
Can you show some of the code you use for rendering and stuff?
Correct me if I’m wrong, but Terraria generates the whole world on the first time it is created, still on the menu, it takes a long time to generate it, but when you’re actually in game, no generation occurs. Does this apply for your game?
Yes it does actually. everything is calculated before gameplay happens
btw here is the code for my generation
r=new Random();//just a random to help generation
decider=r.nextInt(5);//how jagged the terrain will be
//there are no chunks actually being rendered, chunkSize is just a number
//the blocks are just doubles holding simplex noise data
for( x=0; x<chunkSize*25; x+=16){
for( int k=0; k<chunkSize*2;k+=16){
block1=SimplexNoise.noise(x/2,0);
block2=SimplexNoise.noise(x/4,0);
block3=SimplexNoise.noise(x/8,0);
block4=SimplexNoise.noise(x/16,0);
block5=SimplexNoise.noise(x/32,0);
y = (block1+block2+block3+block4+block5*(decider+1);
if(k<4){//this just decides which type of block each tile is
blok=1;
}
if(k>4&&k<4*5){
blok=0;
}
if(k>4*5){
blok=2;
}
addBlock(new TestEnt(x,y+595+k, blok));
}
}
Each testEnt is stored in a linked list then created. each blocks checks to see wheter it is off the screen or not then doesn’t render accordingly
What engine do you use? For fast 2D you should look into libGDX.
Mike
i use the regular java2d but ive pretty much fixed it. i was running the functions of the blocks way to much
Maybe it only renders what’s onscreen, but it’s still calculating what’s offscreen…
In terraria it sures calculates whats offscreen, because if u push a pipe of one side of the world to the other side, you can transport water blocks