LGDX 2D Level Editor - ALPHA 1 - Stress test

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

LGDX 2D Level Editor - ALPHA 1 - Stress test

Postby Obli » Mon Mar 14, 2011 6:06 am

(since this is definitely libgdx related, it belongs to this forum more than to the other :p)

Image

LibGDX 2D Level Editor
------------------------------


Here it is: the first alpha public release of the 2D level editor.

This application is meant to ease the design of levels in 2D. You can define landscape shapes with your mouse, assign them a texture and define collision masks in a few clicks.

I do not have much time to explain the principles (and I will be absent until next sunday, starting now), but the classic way to achieve what you want is the following:

  1. Select your assets directory with the "change res. folder" button.
  2. Create a new shape (remember to define it counterclockwise). You need to close the shape path to exit the creation mode.
  3. Apply it a texture.
  4. Configure and apply it a border if you want to hide the shape edges under a metric ton of tiles.
  5. Define its collision mask with the "set collision mask" button. In this mode, you need to draw circles around vertex groups. These groups must follow the Box2D requirements: they must define a convex hull, and you can't group more than 8 vertices together.
  6. Save your level.

Once done, put all your assets as well as your saved level in the data folder of your game, and add the LevelEditorLoader API to its libraries. Use the following code snippet to load your level. Make sure to call the rebuild() method of the level with the same assets folder you used in the editor. By this I mean that the folder can be different but MUST contain the texture and border files required (since they are saved as relative pathes to the resource directory).

Code: Select all
// First load the level binary file
FileHandle file = Gdx.files.internal("data/test.level");
LevelModel level = new ImportHelper().loadLevel(file);

// Then rebuild it by giving it the path to the same assets folder
// you used in the editor.
FileHandle res = Gdx.files.internal("data/gfx");
level.rebuild(res);


You're done ! Just iterate through the level shapes to render them, like this (of course, you can do some culling by checking the shapes bounding boxes, this is only a trivial inefficient example):

Code: Select all
public static void render(LevelModel level) {
   for (int i=0; i<level.getShapeCount(); i++) {
      ShapeModel shape = level.getShape(i);

      shape.fillTexDef.getTexture().bind();
      shape.getFillMesh().render(GL10.GL_TRIANGLES);
      shape.borderTexDef.getTexture().bind();
      shape.getBorderMesh().render(GL10.GL_TRIANGLES);
   }
}


Enjoy ! And do not hesitate to report the bugs, it's the purpose of this alpha !
Of course, a whole bunch of features are missing, stay tuned for updates ;)
The engine is not at all optimized. You can do a lot on your own (sorting shapes by textures, culling, etc), do not hesitate to give me your best performance tricks, I'll include them as automated processes.

The level editor executable jar:
http://goo.gl/0TK59

The level loader API library:
http://goo.gl/IBhwY
Last edited by Obli on Tue Mar 29, 2011 12:32 pm, edited 3 times in total.
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [APP] LibGDX 2D Level Editor - ALPHA 1

Postby NateS » Mon Mar 14, 2011 8:53 am

I run the desktop JAR, see the window, see the GUI similar to the screenshot, then immediately javaw.exe crashes in nvoglv32.dll. To fix it, I changed your Main.java to this:

Code: Select all
package leveleditor;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.UIManager;

import leveleditor.ui.MainWindow;

public class Main {
   public static void main (String[] args) {
      EventQueue.invokeLater(new Runnable() {
         public void run () {
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            MainWindow mainWindow = new MainWindow();
            sizeAndCenter(mainWindow, 1200, 900);
            mainWindow.validate();
            mainWindow.setVisible(true);
            mainWindow.initRenderer();
            mainWindow.initEvents();
         }
      });
   }

   static void sizeAndCenter (JFrame frame, int w, int h) {
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      int width = Math.min(screenSize.width - 100, w);
      int height = Math.min(screenSize.height - 50, h);
      frame.setSize(width, height);
      int x = (screenSize.width - width) / 2;
      int y = (screenSize.height - height) / 2;
      frame.setLocation(x, y);
   }
}


Attached is the fixed JAR, if anyone else has the same issue.

BTW, you can just call JFrame#setLocationRelativeTo(null) to center the frame on the screen.

You should try to avoid doing things on the UI thread, it makes the app lock up. Eg, if I make my desktop the resource folder, the app locks up for a few seconds.

You might want to do something like this to make it easier for people to see logs:
Code: Select all
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

public class StdLogger {
   private StdLogger () {
   }

   static public void capture (String logFile) {
      try {
         new File(logFile).getParentFile().mkdirs();
         FileOutputStream fileOutput = new FileOutputStream(logFile);
         System.setOut(new PrintStream(new MultiplexOutputStream(System.out, fileOutput), true));
         System.setErr(new PrintStream(new MultiplexOutputStream(System.err, fileOutput), true));
      } catch (FileNotFoundException ex) {
         throw new RuntimeException(ex);
      }
   }

   static private class MultiplexOutputStream extends OutputStream {
      private final OutputStream[] streams;

      public MultiplexOutputStream (OutputStream... streams) {
         if (streams == null) throw new IllegalArgumentException("streams cannot be null.");
         this.streams = streams;
      }

      public void write (int b) throws IOException {
         for (int i = 0; i < streams.length; i++)
            streams[i].write(b);
      }

      public void write (byte[] b, int off, int len) throws IOException {
         for (int i = 0; i < streams.length; i++)
            streams[i].write(b, off, len);
      }
   }
}


If I apply a texture, the GL rendering thread crashes. After digging out the logs, my image wasn't POT.

Ok, got a shape textured. Cool! :D I can move and rotate it, how about scale (in either direction, or both)?

I created two shapes, but seem unable to select the first one I made.

Looks like a very neat tool. Needs some docs, definitely, as I'm not sure what some of this stuff does. :)
Attachments
LevelEditor.jar
(290.3 KiB) Downloaded 584 times
NateS
 
Posts: 1980
Joined: Fri Nov 12, 2010 11:08 am

Re: [APP] LibGDX 2D Level Editor - ALPHA 1

Postby Obli » Mon Mar 14, 2011 5:39 pm

Thanks for the report !

It's strange that the app crashes at startup. I tested it at home, at work, and on the computer of my brother (all win7)...

About the texture POT, normaly when you select an image file in the resource list, it should display a warning in the preview panel and clear the selection. I'll double check this.

About shape scaling: just use the shape bounding box handles to resize it, as shown in the previous screenshot. It will not "scale" the shape, but "resize" it, changing the meshes texel positions to avoid changing the texture zoom. I find it more consistent with what a level should be.

You are unable to select the first shape ? Are you in Idle mode or still in shape create or shape edit mode or? To go back to the idle mode, click anywhere but near a shape vertex.

Anyway, it needs a big video tutorial of course, as well as a lot of coursedocumentation :-D
Thanks again, I never ever encountered your bugs, nor did my brother. I'll check the uploaded jars ! Can't do it for now, I'm on holidays, writing this with my android phone :-P
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [APP] LibGDX 2D Level Editor - ALPHA 1

Postby saidinstouch » Mon Mar 14, 2011 5:45 pm

I have a win7 machine (core i3 540 I believe) with an nVidia 450 gts and no crash here. The program runs at around 63fps with no textures or anything loaded into it. I can create shapes and collision maps (haven't tried loading anything into my game yet). Tonight I will play around with some image files to use as fake textures since I don't have anything created and let you know how it performs for me.

I am VERY excited about this tool and as I've said before it released at the perfect time for me since I am at the level design/implementation stage of my game!
saidinstouch
 
Posts: 79
Joined: Wed Feb 16, 2011 7:44 pm

Re: [APP] LibGDX 2D Level Editor - ALPHA 1

Postby Mercury » Mon Mar 14, 2011 7:33 pm

Yeaa, the editor is finally here :) This tool would really help me with my game. Thanks Obli for this.
Also it would be nice to create a youtube video on how to use this tool ... :ugeek:
Mercury
 
Posts: 27
Joined: Sat Oct 23, 2010 10:03 am
Location: Serbia and Montenegro, Budva

Re: LibGDX 2D Level Editor - ALPHA 1 - Stress test

Postby Obli » Thu Mar 17, 2011 4:28 pm

Back from the holidays (well, much like the "let's meet the last people involved in our weeding" plan) ! The youtube video is coming. Can someone tell me what is the easiest free tool to record myself playing with the application ? Thanks. :ugeek:

Anyways, nobody else than Nates has a crash or bug report to give me, or maybe a suggestion, hint or advice ?
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: LibGDX 2D Level Editor - ALPHA 1 - Stress test

Postby csshenouda » Fri Mar 18, 2011 7:53 am

Ok, this might be a total noob question but is there a way to edit the shapes after I have applied a texture and border? If I don't set a border it's fine obviously.
Edit: Actually I can't reproduce it anymore :?
csshenouda
 
Posts: 7
Joined: Fri Mar 11, 2011 10:04 am

Re: LibGDX 2D Level Editor - ALPHA 1 - Stress test

Postby Obli » Fri Mar 18, 2011 11:36 am

You can edit a shape by selecting it and clicking on the "edit" button, in the right panel, or you can just double-click on the shape.
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: LibGDX 2D Level Editor - ALPHA 1 - Stress test

Postby tamas305 » Fri Mar 18, 2011 1:10 pm

I had the same issue that Nate had with javaw.exe crashing on startup, but it seems as though his solution did not work for me as the fixed version would just not open. Running Java 6 22-b04 on a x64 win7 ultimate machine.
tamas305
 
Posts: 108
Joined: Sat Nov 06, 2010 1:51 pm

Re: LibGDX 2D Level Editor - ALPHA 1 - Stress test

Postby Obli » Fri Mar 18, 2011 1:13 pm

Mmm, it may be due to a java 64 bits runtime. I only checked with a 32 bits runtime (it was compiled with a 32 bits jdk on a Win7 64 bits machine). I'll check that, thanks !
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Next

Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest