android - Libgdx Rendering Textures vs Sprites -


I am trying to create my first game with Libgdx and Box2d. There is a similar concept in the game such as flappy bird My problem is projecting the pipes.

I have tried to draw the rectangles and then have portrayed the new phantom, which can be shaped in different pipe sizes every time it is called the render method. The issue is that I can not handle the texture when the rectangle leaves the screen because it will also create all other rectangles that still lose their texture if I do not settle texture , Once the screen leaves, the game will slow down after 20 seconds.

The second option is to use around 10 different textures for different pipe sizes, but still the issue of texture disposal.

I appreciate any suggestions on how to render different pipe sizes efficiently. I have attached my render code below

  @ Override Public Zero Render (Float Delta) {Gdx.gl.glClearColor (0,0,0,0,0,0); Gdx.gl.glClear (GL10.GL_COLOR_BUFFER_BIT); World.step (BOX_STEP, BOX_VELOCITY_ITERATIONS, BOX_POSITION_ITERATIONS); Batch.setProjectionMatrix (camera.combined); Batch.begin (); //background.setPosition(camera.position.x-camera.viewportwidth/2, camera.position.y-14); //background.draw(batch); Batch.end (); //bg1.update (); //bg2.update (); UpdateAnimation (); If ((timuratel. Nano time) / 10) - (last drip time / 10) & gt; 300000000) createPipes (); Batch.begin (); For (rectangle rainlight: raindrops) {pipe_top.set size (4, raindrop high.); Pipe_top.setPosition (raindrop.x, raindrop.y); Pipe_top.draw (batch); Pipe_bottom.setSize (4, raindrop.height); Pipe_bottom.setPosition (raindrop.x, camera.position.y + (camera.viewportHeight / 2-pipe_bottom.getHeight ())); Pipe_bottom.draw (batch); } Batch.and (); If (pipe.etx () <0) {pipe.ttictions (). Remove (); } Iterator & lt; Rectangle & gt; IARAR = rain drop While (iter.hasNext ()) {rectangle raindrop = iter.next (); Raindrop.x - = 4 * Gdx.graphics.getDeltaTime (); If (raindrop.x & lt; -35) iter.remove (); } Debug.render (world, camera.combined); } You must keep the render () method as fast as possible.  

In addition, you do not need many sprites in the form of rain drops, you can reuse the same phantom, change it, position and shape and drag it several times.

Hope it helps.


Comments