Slick Forums

Discuss the Slick 2D Library
It is currently Thu Jun 20, 2013 11:51 am

All times are UTC




Post new topic Reply to topic  [ 170 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11, 12  Next
Author Message
 Post subject: Re: MarteEngine
PostPosted: Wed Nov 23, 2011 9:43 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
If I read the Nifty instructions right on how to work with Slick (here: http://nifty-gui.lessvoid.com/archives/91) you will need to implement your own Nifty InputSystem handler class and call that in your World subclass update method.
Quote from the link above:
Quote:
Handling mouse events are a bit trickier because they are handled through the InputSystem interface which you need to call the Nifty constructor with. But creating an implementation of the InputSystem is easy because at the moment it only consists of one method that Nifty uses to request a List of current available MouseEvents. So you’re implementation can decide when and what mouse events get through to Nifty in the InputSystem-Implementation.


See this thread in the Nifty GUI forums for (maybe) more help:
http://sourceforge.net/projects/nifty-gui/forums/forum/807893/topic/3803773

Keep us updated on your progress, please!

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Thu Nov 24, 2011 2:05 am 
Offline

Joined: Mon Mar 21, 2011 4:22 pm
Posts: 32
Location: United States
I got it working. I had some look at this thread: viewtopic.php?p=20588 and has helped a lot. The mouse events all worked and focusing, etc. But it wasn't executing the event I needed. Spent hours trying to fix this for the most simplest fix ever.

instead of (I have this class as an inner class)

Code:
   class MainMenuController implements ScreenController {

        @NiftyEventSubscriber(id = "TestButton1")
        public void testButton1(final String id, final ButtonClickedEvent event) {
            System.out.println("here");
        }

        @Override
        public void bind(Nifty nifty, Screen screen) {
        }

        @Override
        public void onStartScreen() {
        }

        @Override
        public void onEndScreen() {
        }
    }


change to

Code:
   public class MainMenuController implements ScreenController {

        @NiftyEventSubscriber(id = "TestButton1")
        public void testButton1(final String id, final ButtonClickedEvent event) {
            System.out.println("here");
        }

        @Override
        public void bind(Nifty nifty, Screen screen) {
        }

        @Override
        public void onStartScreen() {
        }

        @Override
        public void onEndScreen() {
        }
    }


I guess its not a big deal if you don't make it an inner class. But I had left out the public keyword in front of the class keyword, and it wouldn't work! I had no idea why. I found the resolution at
http://sourceforge.net/projects/nifty-g ... ic/4645804


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Fri Nov 25, 2011 2:14 am 
Offline

Joined: Mon Mar 21, 2011 4:22 pm
Posts: 32
Location: United States
I ended up having nifty gui work perfectly with marte engine.

What I did is create a NiftyWorld class which extends World and have all the nasty nifty gui code in there. I got most of the code from the NiftyBasicGame class and altered it a bit to work with marte. I also created a class for the MouseEvents which I got the code from here: viewtopic.php?f=3&t=3436 The nifty libraries I used are nifty-1.3.jar, nifty-lwjgl-renderer-1.3,jar (not the slick renderer), nifty-default-control-1.3.jar, and nifty-default-controls-1.3.jar. The only thing that doesn't really work is when using a textfield, you can't hold, for an example, backspace to delete all the characters. You have to repeatedly press it to delete them all instead of just holding it in. I am not sure how to fix that. Its a problem for any key.

Code:
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyInputConsumer;
import de.lessvoid.nifty.input.keyboard.KeyboardInputEvent;
import de.lessvoid.nifty.nulldevice.NullSoundDevice;
import de.lessvoid.nifty.renderer.lwjgl.input.LwjglKeyboardInputEventCreator;
import de.lessvoid.nifty.renderer.lwjgl.render.LwjglRenderDevice;
import de.lessvoid.nifty.spi.input.InputSystem;
import de.lessvoid.nifty.tools.TimeProvider;
import it.randomtower.engine.World;
import java.util.ArrayList;
import java.util.List;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.opengl.SlickCallable;
import org.newdawn.slick.state.StateBasedGame;

/**
* A class for using Nifty-gui with Marte Engine's world class.
* @author Colt
* @version Nov 24, 2011
*/
public class NiftyWorld extends World {

    /** The maximum number of controllers supported by the basic game */
    private static final int MAX_CONTROLLERS = 20;
    /** The maximum number of controller buttons supported by the basic game */
    private static final int MAX_CONTROLLER_BUTTONS = 100;
    /** The state of the left control */
    protected boolean[] controllerLeft = new boolean[MAX_CONTROLLERS];
    /** The state of the right control */
    protected boolean[] controllerRight = new boolean[MAX_CONTROLLERS];
    /** The state of the up control */
    protected boolean[] controllerUp = new boolean[MAX_CONTROLLERS];
    /** The state of the down control */
    protected boolean[] controllerDown = new boolean[MAX_CONTROLLERS];
    /** The state of the button controlls */
    protected boolean[][] controllerButton = new boolean[MAX_CONTROLLERS][MAX_CONTROLLER_BUTTONS];
    protected Nifty nifty;
    protected int mouseX;
    protected int mouseY;
    private List<MouseEvent> mouseEvents = new ArrayList<MouseEvent>();
    private List<KeyboardInputEvent> keyEvents = new ArrayList<KeyboardInputEvent>();
    private LwjglKeyboardInputEventCreator inputEventCreator = new LwjglKeyboardInputEventCreator();
    private boolean mouseDown;

    /**
     * Creates a world with the use of Nifty - GUI.
     * @param id
     * @param gc
     */
    public NiftyWorld(int id, GameContainer gc) {
        super(id, gc);
    }

    /**
     * @see org.newdawn.slick.InputListener#setInput(org.newdawn.slick.Input)
     */
    @Override
    public void setInput(Input input) {
    }

    /**
     * @see org.newdawn.slick.Game#closeRequested()
     */
    public boolean closeRequested() {
        return true;
    }

    @Override
    public void init(GameContainer container, StateBasedGame sbg) throws SlickException {

        nifty = new Nifty(new LwjglRenderDevice(), new NullSoundDevice(), new InputSystem() {

            @Override
            public void forwardEvents(final NiftyInputConsumer inputEventConsumer) {
                for (MouseEvent event : mouseEvents) {
                    event.processMouseEvents(inputEventConsumer);
                }
                mouseEvents.clear();

                for (KeyboardInputEvent event : keyEvents) {
                    inputEventConsumer.processKeyboardEvent(event);
                }
                keyEvents.clear();
            }

            @Override
            public void setMousePosition(int x, int y) {
            }
        }, new TimeProvider());
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
        nifty.update();
    }

    @Override
    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
        SlickCallable.enterSafeBlock();
        nifty.render(true);
        SlickCallable.leaveSafeBlock();
    }

    private void forwardMouseEventToNifty(final int mouseX, final int mouseY, final boolean mouseDown) {
        mouseEvents.add(new MouseEvent(mouseX, mouseY, mouseDown, 0));
    }

    /**
     * @see org.newdawn.slick.InputListener#mouseMoved(int, int, int, int)
     */
    @Override
    public void mouseMoved(final int oldx, final int oldy, final int newx, final int newy) {
        mouseX = newx;
        mouseY = newy;
        forwardMouseEventToNifty(mouseX, mouseY, mouseDown);
    }

    /**
     * @see org.newdawn.slick.InputListener#mousePressed(int, int, int)
     */
    @Override
    public void mousePressed(final int button, final int x, final int y) {
        mouseX = x;
        mouseY = y;
        mouseDown = true;
        forwardMouseEventToNifty(mouseX, mouseY, mouseDown);
    }

    /**
     * @see org.newdawn.slick.InputListener#mouseReleased(int, int, int)
     */
    @Override
    public void mouseReleased(final int button, final int x, final int y) {
        mouseX = x;
        mouseY = y;
        mouseDown = false;
        forwardMouseEventToNifty(mouseX, mouseY, mouseDown);
    }

    /**
     * @see org.newdawn.slick.InputListener#keyPressed(int, char)
     */
    @Override
    public void keyPressed(final int key, final char c) {
        keyEvents.add(inputEventCreator.createEvent(key, c, true));
    }

    /**
     * @see org.newdawn.slick.InputListener#keyReleased(int, char)
     */
    @Override
    public void keyReleased(final int key, final char c) {
        keyEvents.add(inputEventCreator.createEvent(key, c, false));
    }

    /**
     * @see org.newdawn.slick.InputListener#mouseDragged(int, int, int, int)
     */
    @Override
    public void mouseDragged(int oldx, int oldy, int newx, int newy) {
    }

    /**
     * @see org.newdawn.slick.InputListener#mouseClicked(int, int, int, int)
     */
    @Override
    public void mouseClicked(int button, int x, int y, int clickCount) {
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerButtonPressed(int, int)
     */
    @Override
    public void controllerButtonPressed(int controller, int button) {
        controllerButton[controller][button] = true;
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerButtonReleased(int, int)
     */
    @Override
    public void controllerButtonReleased(int controller, int button) {
        controllerButton[controller][button] = false;
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerDownPressed(int)
     */
    @Override
    public void controllerDownPressed(int controller) {
        controllerDown[controller] = true;
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerDownReleased(int)
     */
    @Override
    public void controllerDownReleased(int controller) {
        controllerDown[controller] = false;
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerLeftPressed(int)
     */
    @Override
    public void controllerLeftPressed(int controller) {
        controllerLeft[controller] = true;
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerLeftReleased(int)
     */
    @Override
    public void controllerLeftReleased(int controller) {
        controllerLeft[controller] = false;
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerRightPressed(int)
     */
    @Override
    public void controllerRightPressed(int controller) {
        controllerRight[controller] = true;
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerRightReleased(int)
     */
    @Override
    public void controllerRightReleased(int controller) {
        controllerRight[controller] = false;
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerUpPressed(int)
     */
    @Override
    public void controllerUpPressed(int controller) {
        controllerUp[controller] = true;
    }

    /**
     * @see org.newdawn.slick.InputListener#controllerUpReleased(int)
     */
    @Override
    public void controllerUpReleased(int controller) {
        controllerUp[controller] = false;
    }

    /**
     * @see org.newdawn.slick.InputListener#mouseWheelMoved(int)
     */
    @Override
    public void mouseWheelMoved(int change) {
    }

    /**
     * @see org.newdawn.slick.InputListener#isAcceptingInput()
     */
    @Override
    public boolean isAcceptingInput() {
        return true;
    }

    /**
     * @see org.newdawn.slick.InputListener#inputEnded()
     */
    @Override
    public void inputEnded() {
    }

    /**
     * @see org.newdawn.slick.ControlledInputReciever#inputStarted()
     */
    @Override
    public void inputStarted() {
    }
}


Code:
import de.lessvoid.nifty.NiftyInputConsumer;

/**
*
* @author Colt
* @version Nov 24, 2011
*/
public class MouseEvent {

    private int mouseX;
    private int mouseY;
    private int mouseWheel;
    private int button;
    private boolean buttonDown;

    public MouseEvent(final int mouseX, final int mouseY, final boolean mouseDown, final int mouseButton) {
        this.mouseX = mouseX;
        this.mouseY = mouseY;
        this.buttonDown = mouseDown;
        this.button = mouseButton;
        this.mouseWheel = 0;
    }

    public void processMouseEvents(final NiftyInputConsumer inputEventConsumer) {
        inputEventConsumer.processMouseEvent(mouseX, mouseY, mouseWheel, button, buttonDown);
    }
}


So if anyone wants to use Nifty-gui with marte engine and they don't wanna go through the hassle of getting it to work correctly, just put this two classes in your project. When you create a new state just extend NiftyWorld and then the rest is up to you! Basic example:

Code:
import de.lessvoid.nifty.builder.ElementBuilder.Align;
import de.lessvoid.nifty.builder.ElementBuilder.VAlign;
import de.lessvoid.nifty.builder.LayerBuilder;
import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.builder.ScreenBuilder;
import de.lessvoid.nifty.controls.button.builder.ButtonBuilder;
import de.lessvoid.nifty.controls.label.builder.LabelBuilder;
import de.lessvoid.nifty.controls.textfield.builder.TextFieldBuilder;
import de.lessvoid.nifty.screen.Screen;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

/**
*
* @author Colt
* @version Nov 24, 2011
*/
public class WorldExample extends NiftyWorld {

    public WorldExample(int id, GameContainer gc) {
        super(id, gc);
    }

    @Override
    public void init(GameContainer gc, final StateBasedGame sbg) throws SlickException {
        super.init(gc, sbg);
        //you still have to lood the controller and style files
        //you don't have to create a new nifty object. you can use the nifty object from NiftyWorld
        nifty.loadStyleFile("nifty-default-styles.xml");
        nifty.loadControlFile("nifty-default-controls.xml");

        Screen mainScreen = new ScreenBuilder("main") {

            {
                //you have to create a worldexamplecontroller class
                controller(new WorldExampleController(sbg));
                layer(new LayerBuilder("foreground") {

                    {
                        childLayoutCenter();
                        backgroundColor("#0000");
                        panel(new PanelBuilder("namePanel") {

                            {
                                height("130px");
                                width("200px");
                                style("nifty-panel");
                                align(Align.Center);
                                valign(VAlign.Center);
                                childLayoutVertical();
                                control(new LabelBuilder("nameLbl") {

                                    {
                                        label("Enter infection name");
                                        alignCenter();
                                    }
                                });
                                control(new TextFieldBuilder("name") {

                                    {
                                        width("120px");
                                        height("20px");
                                        alignCenter();
                                        paddingBottom("40px");
                                    }
                                });

                                control(new ButtonBuilder("next") {

                                    {

                                        label("Next");
                                        width("120px");
                                        height("40px");
                                        alignCenter();
                                    }
                                });

                            }
                        });

                    }
                });
            }
        }.build(nifty);
        nifty.addScreen("mainScreen", mainScreen);
        nifty.gotoScreen("mainScreen");
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
        super.update(gc, sbg, delta);
    }

    @Override
    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
        super.render(gc, sbg, g);

    }
}


Hope this helps, because I had a lot of trouble with this for some reason :D


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Fri Nov 25, 2011 6:56 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
That's awesome!

Next step would be to have Nifty GUI and game play/entities in one world, maybe?!

Thanks a lot for sharing the code!

Cheers,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Fri Nov 25, 2011 4:50 pm 
Offline

Joined: Mon Mar 21, 2011 4:22 pm
Posts: 32
Location: United States
Tommy wrote:
That's awesome!

Next step would be to have Nifty GUI and game play/entities in one world, maybe?!

Thanks a lot for sharing the code!

Cheers,
Tommy

I am actually trying to get that working now. Hopefully I get it working soon :p


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Fri Feb 10, 2012 1:54 am 
Offline

Joined: Thu Jan 26, 2012 5:40 pm
Posts: 79
I'm trying out MarteEngine but there's no javadoc? How do I tell what methods are there and what the constructors are? Sorry if the answer seems obvious, I'm a dirty noob.


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Fri Feb 10, 2012 3:07 am 
Offline

Joined: Tue Aug 16, 2011 2:17 am
Posts: 31
Location: Phoenix
eulogy1337 wrote:
I'm trying out MarteEngine but there's no javadoc? How do I tell what methods are there and what the constructors are? Sorry if the answer seems obvious, I'm a dirty noob.

One option is to check the source code, it's mostly documented. The wiki page will also help a lot! https://github.com/Gornova/MarteEngine/wiki


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Fri Feb 10, 2012 9:22 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1317
Location: Italy
My suggestion is to read wiki then download source code and learn from examples

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Wed Feb 15, 2012 2:56 pm 
Offline

Joined: Thu Jan 26, 2012 5:40 pm
Posts: 79
Okay, I've got my code ported over to Marte and got some nice use out of what it offers. I noticed that entity has a depth variable, but I have no idea how to use it. I want to sort my entities based on the Y axis, but I'm having trouble finding any kind of resources on this.


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Wed Feb 15, 2012 3:02 pm 
Offline

Joined: Tue Aug 16, 2011 2:17 am
Posts: 31
Location: Phoenix
eulogy1337 wrote:
Okay, I've got my code ported over to Marte and got some nice use out of what it offers. I noticed that entity has a depth variable, but I have no idea how to use it. I want to sort my entities based on the Y axis, but I'm having trouble finding any kind of resources on this.

The depth determines the highest image on the screen. A depth = 100 would overlap a image with depth =50. Not sure.if that's 100% right but I can check for sure later.


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Wed Feb 15, 2012 4:13 pm 
Offline

Joined: Thu Jan 26, 2012 5:40 pm
Posts: 79
Nightmare wrote:
eulogy1337 wrote:
Okay, I've got my code ported over to Marte and got some nice use out of what it offers. I noticed that entity has a depth variable, but I have no idea how to use it. I want to sort my entities based on the Y axis, but I'm having trouble finding any kind of resources on this.

The depth determines the highest image on the screen. A depth = 100 would overlap a image with depth =50. Not sure.if that's 100% right but I can check for sure later.


That's what I gathered, so in my entities I want sorted I have

Code:
depth = (int)y;


in my update methods. Printing the depth value shows that they are updating correctly, but they don't change what order they're rendered in. Not sure how to do that part. Do I need to use the method compareTo? How would I use it?

Also, I'm using my own Camera class, is that an issue? I'm also using SpriteSheets and MarteEngine's animation system.


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Wed Feb 15, 2012 7:39 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
I'm afraid you've found a bug in our Marte Engine :(

There is currently no way to resort the entities if you change the depth of an entity after it's creation.

A workaround would be to add an invisible entity to the World which forces a resort of the existing entities. Of course you would need to remove it a bit later.

Sorry for now,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Wed Feb 15, 2012 7:54 pm 
Offline

Joined: Thu Jan 26, 2012 5:40 pm
Posts: 79
Tommy wrote:
I'm afraid you've found a bug in our Marte Engine :(

There is currently no way to resort the entities if you change the depth of an entity after it's creation.

A workaround would be to add an invisible entity to the World which forces a resort of the existing entities. Of course you would need to remove it a bit later.

Sorry for now,
Tommy


Ah well, at least I'm no longer frustrated thinking I was doing something wrong. Thank you so much for letting me know! Otherwise it has been a blast to work with MarteEngine over Artemis and/or writing the code myself - thanks for making it :)

I followed your advice and it's almost working. Thanks!


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Wed Feb 15, 2012 9:30 pm 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1317
Location: Italy
@eulogy1337 what sort of game are you doing with MarteEngine?

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Wed Feb 15, 2012 11:19 pm 
Offline

Joined: Thu Jan 26, 2012 5:40 pm
Posts: 79
Gornova81 wrote:
@eulogy1337 what sort of game are you doing with MarteEngine?

Action RPG, like classic Zelda games.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 170 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11, 12  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group