Hello Guest

Author Topic: Using SFML & Otter  (Read 3277 times)

0 Members and 1 Guest are viewing this topic.

CEJ

  • Member
  • Posts: 4
    • View Profile
    • personal site
Using SFML & Otter
« on: May 28, 2014, 10:11:44 AM »
I'm not sure if this is a dumb question, but is it possible to access native SFML methods too when using otter? Do I have to add SFML.net and reference that to the project too or is that superfluous? I only ask because I haven't used Otter or SFML before, I tried Otter first time yesterday then I read that it was still in development.

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Using SFML & Otter
« Reply #1 on: May 28, 2014, 02:37:11 PM »
You can use SFML if you just include the proper dlls and references.  You might have the best luck extending the Graphic class if you're looking to implement your own rendering stuff.  The hope with Otter though is to safely hide SFML behind the scenes so that it's no longer necessary to use any SFML code to get a game up and running.

So although Otter is still under development, it's getting pretty close to version 1.0, so if you have any specific hang ups or things you want to do with SFML then let me know and I can hopefully figure out the best way to go about it.

CEJ

  • Member
  • Posts: 4
    • View Profile
    • personal site
Re: Using SFML & Otter
« Reply #2 on: May 28, 2014, 05:17:44 PM »
Alright, yeah ok. I might not want to bother with SFML, just thought maybe I should try to get some familiarity with it too. But Otter looks pretty rad so!

I'm probably just a being a big noob. The code below didn't work as I had hoped, calling AddGraphic and MouseX,MouseY from another class.method doesn't work? I really don't know what I'm doing with this progamming-biz, but it's pretty fun. Anyway, if I copy the method into the same class, that works like a charm, my awesome orange mouse-cursor appears and everything is sunshine. But it would be nice to do that code in just one scene you know?

public class TitleScene : Scene
Code: [Select]
            GameScene other = new GameScene();
            other.myCursor(CURSOR_IMG);


public class GameScene : Scene
Code: [Select]
        public void myCursor(Image name)
        {
            name.CenterOrigin();
            name.X = MouseX;
            name.Y = MouseY;
            AddGraphic(name);
        }

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Using SFML & Otter
« Reply #3 on: May 29, 2014, 11:06:37 AM »
I think the issue with that code is that it's only executing once.  You have a method that will take an image and set it to the mouse's position, but that only happens once, so it's not going to stay at your mouse position.  If you want an image to be at your mouse coordinates at all times, you need to do that in an update function.

Something like this:
Code: [Select]
public override void Update() {
base.Update();
// Assuming that CursorImage is a reference to the Image that you want to be your cursor.
CursorImage.X = MouseX;
CursorImage.Y = MouseY;
}
In your Scene should be able to do that.  Alternatively, you could make an Entity to represent your cursor, where the Entity would have the graphic for the cursor, and always set its X and Y position to the MouseX and MouseY.

CEJ

  • Member
  • Posts: 4
    • View Profile
    • personal site
Re: Using SFML & Otter
« Reply #4 on: June 01, 2014, 12:55:28 PM »
Thanks, also another thing. I'm trying to make a image viewer, which loads one or more images, I have it sort of working.

I want to be able to start the app when the user right-clicks the image, 'Open With.. Choose Default Program". I have this part working.

However, when I add assets to the project, images, shaders, anything like that, it stops working.

Code: [Select]
Failed to load image "Assets/imgviewer.png". Reason : Unable to open file
Unhandled Exception: SFML.LoadingFailedException: Failed to load image from file
Assets/imgviewer.png at SFML.Graphics.Image..ctor<string filename> at Otter.Game.SetIcon<String
source> in c:\Users\Jocke\Documents\Visual Studio 2013\ImageViewer\Imageviewer\Otter
\Core\Game.cs:line 993 at ImageViewer.Program.Main<String[] args> in c:\Users\Jocke\Documents
\Visual Studio 2013\Projects\ImageViewer\ImageViewer\Program.cs:line 40

At the moment I only have one image and one shader. I have both set to "Copy if newer". I also have all of the otter files set to 'copy if newer' as well.

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Using SFML & Otter
« Reply #5 on: June 01, 2014, 02:55:06 PM »
Hmm the only thing that the error is indicating is that the relative path to the file doesn't exist.  Can you verify that the files that you're trying to load all exist in the folder where the .exe is running from?