[lib] Screen Editor -- Place and size your sprites IN-APP !

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

[lib] Screen Editor -- Place and size your sprites IN-APP !

Postby Obli » Sun Aug 14, 2011 9:52 am

Hello!

I needed to position precisely many sprites for my game intro screen, and that was quite a tedious and boring thing to do. Especially since my screen viewport is expressed in meters and has nothing to do with pixels. Therefore, I needed to convert my image positions from their pixel positions in my graphics editor to the game viewport... BORING!

As a result, I decided to create a library to help me position everything in-game, with the mouse. And guess what, it's done and I want to share :mrgreen:
Since an image is better than 1000 lines of text, have a look at the strip below if you need to be convinced that you desperately need this lib ;)

Be aware that since I only work with Sprite and OrthographicCamera, I made the library to support only those. If you want Actor support, you can edit the source code and change all "Sprite" declarations in the source code to "Actor". If there is a real desperate need for Actor support, you should send a thousand mail to Mario by requesting that Sprite and Actor both inherit from a "Drawable2D" interface that should define a position and a size :mrgreen:
The only thing I can do on my side is either to write a new ScreenEditor for every class to support (and welcome the maintainability nightmare), or create a proxy hiding the supported classes. I think I'll investigate this way.

Features:
  • Lets you place and resize all your sprites with the mouse,
  • Lets you zoom and pan the scene for better comfort,
  • Creates a file where everything gets stored and loaded on every other launches,
  • Disabling the editor in the future only requires to comment 1 line from your code,
  • A disabled editor does not use any resource!

Link to library zip file (contains jar library and sources):
http://goo.gl/vXlFm

Usage example:
Code: Select all
public class MenuScreen implements Screen {
   ...
   private final ScreenEditor screenEditor;

   public MenuScreen() {
      ...
      
      // First, create a ScreenEditor and pass it:
      // 1. The path where stuff will be saved/loaded
      // 2. The current screen camera
      // 3. An ObjectList containing every object you want to interact with
      
      screenEditor = new ScreenEditor("data/screeneditor-menu.bin", camera, new ObjectList()
         .add(sunSprite, "sunSprite")
         .add(earthSprite, "earthSprite")
         .add(earthLightSprite, "earthLightSprite")
         .add(heroSprite, "heroSprite"));
      
      // Then, load the editor. Every previously saved stuff will get loaded
      // and objects will be positioned and sized accordingly. If this is the
      // first launch, this call will do nothing.
      
      screenEditor.load();
   }

   @Override
   public void show() {
      ...
      
      // The editor need to be enabled to show its UI. Otherwise, it only
      // loads stuff and returns. Therefore, once you're happy with your
      // results, this is the ONLY LINE you need to remove or comment.
      
      screenEditor.enable();
   }

   @Override
   public void render(float delta) {
      ...
      
      // Don't forget to call the render() method if you want the editor to
      // draw an overlay. If the editor is not enabled, this call returns
      // immediatly, so you can leave it there safely.
      
      screenEditor.render();
   }
}


Image
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [lib] Screen Editor -- Place and size your sprites IN-AP

Postby mzechner » Sun Aug 14, 2011 11:26 pm

Sweetness :D
mzechner
Site Admin
 
Posts: 4875
Joined: Sat Jul 10, 2010 3:50 pm

Re: [lib] Screen Editor -- Place and size your sprites IN-AP

Postby radioking » Tue Aug 16, 2011 9:45 am

Obli wrote:As a result, I decided to create a library to help me position everything in-game, with the mouse. And guess what, it's done and I want to share :mrgreen:
Since an image is better than 1000 lines of text, have a look at the strip below if you need to be convinced that you desperately need this lib ;)


Très cool :D

Obli wrote:If you want Actor support, you can edit the source code and change all "Sprite" declarations in the source code to "Actor". If there is a real desperate need for Actor support, you should send a thousand mail to Mario by requesting that Sprite and Actor both inherit from a "Drawable2D" interface that should define a position and a size :mrgreen:


+1

Will this be available for Android backend with Touchscreen support instead of mouse? :mrgreen:
Please "give sth. back" to community and contribute your knowledge to our libgdx-users project community wiki:
http://code.google.com/p/libgdx-users/
Please see Mario's note on User Wiki 2.0: http://www.badlogicgames.com/wordpress/?p=2411
radioking
 
Posts: 284
Joined: Wed Aug 03, 2011 10:28 am

Re: [lib] Screen Editor -- Place and size your sprites IN-AP

Postby t4ils » Tue Aug 16, 2011 12:38 pm

Great Obli =D

I really like the way you make tools to help people developing games faster and better ;)

Keep up the good work :)
t4ils
 
Posts: 122
Joined: Thu Mar 03, 2011 8:54 am
Location: Savigny-sur-Orge, France

Re: [lib] Screen Editor -- Place and size your sprites IN-AP

Postby BurningHand » Tue Aug 16, 2011 1:01 pm

t4ils wrote:Great Obli =D

I really like the way you make tools to help people developing games faster and better ;)

Keep up the good work :)


Indeed. Very cool. May I make a suggestion for the next tool? A tool that makes me a better graphics designer, :lol:.
IRC: nexsoftware / mobidevelop; GitHub: MobiDevelop;
BurningHand
 
Posts: 2812
Joined: Mon Oct 25, 2010 4:35 am

Re: [lib] Screen Editor -- Place and size your sprites IN-AP

Postby Saurav » Tue Aug 16, 2011 1:48 pm

I second BurningHand's suggestion ;)
Saurav
 
Posts: 623
Joined: Sun Feb 27, 2011 7:59 pm

Re: [lib] Screen Editor -- Place and size your sprites IN-AP

Postby Obli » Wed Aug 17, 2011 12:28 pm

Thanks! I'm glad it can help someone as much as it helps me currently :)
I'll add a proxy for the interactive objects so it can support anything, from Sprites to Actors, Cameras, etc.
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [lib] Screen Editor -- Place and size your sprites IN-AP

Postby VBCoder68 » Sun Oct 30, 2011 11:59 pm

This is an awesome application - Thanks!!!

I do have one question though. I see that screen editor draws bounding boxes for you around your sprites and lets you drag them around. My question is how does the host application know where the bounding boxes have been dragged to so it can render the sprite inside it?

thanks again,

Mike
VBCoder68
 
Posts: 17
Joined: Wed May 18, 2011 3:43 pm

Re: [lib] Screen Editor -- Place and size your sprites IN-AP

Postby VBCoder68 » Mon Oct 31, 2011 5:27 pm

Okay. That was a dumb question. I just added all of my sprites to the ObjectList before passing it to the ScreenEditor's constructor. Now, I'm running into a different issue. The sprite fits perfectly within the bounding box until i either try to scroll or reset the camera. At that point, the sprite jumps down about 25% down in the bounding box. I'm guessing I'm passing the wrong camera matrix to the sprite batch or something.

BTW, as I'm sure you can tell, I am a noob to LibGDX.

Here is my render method code.

thanks,

mike

Code: Select all
@Override public void render () {
Gdx.gl.glClearColor(0, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.setProjectionMatrix(camera.combined);
// Drawing goes here!
for (Sprite o : objSprites.objects) {
batch.draw(txtTurnStall, o.getX(), o.getY(), o.getWidth(),o.getHeight());
}
batch.end();

// Don't forget to call the render() method if you want the editor to
// draw an overlay. If the editor is not enabled, this call returns
// immediately, so you can leave it there safely.

screenEditor.render();
}
VBCoder68
 
Posts: 17
Joined: Wed May 18, 2011 3:43 pm

Re: [lib] Screen Editor -- Place and size your sprites IN-AP

Postby Obli » Wed Nov 02, 2011 10:26 am

batch.setProjectionMatrix must be called before batch.begin :mrgreen:
Also, you can just use sprite.draw(batch) method instead of using the batch call.

Code: Select all
batch.setProjectionMatrix(camera.combined);
batch.begin();
// Drawing goes here!
for (Sprite o : objSprites.objects)
    o.draw(batch);
batch.end();


Tell me if it fixed your problem.

Anyway, I have a much more improved version of this lib for my own usage. I'll release it.
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