Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Nbxy

Pages: [1]
1
General / Re: Mouse Wheel Scroll Zoom (C# / SFML.Net)
« on: April 26, 2014, 07:12:36 pm »
Thank you Laurent for your input. I got my mouse wheel zoom feature working beautifully. As there are zero examples on the subject in the past topics I'm going to go ahead and make this one a learning experience for everyone who are seeking for this kind zoom feature in the future.
Quote
public static class Game
{
       static float gameZoom = 1;

       static void OnMouseScroll(object sender, EventArgs e)
       {
                RenderWindow window = (RenderWindow)sender;
                MouseWheelEventArgs mouseEvent = (MouseWheelEventArgs)e;
                gameZoom -= 0.05f * mouseEvent.Delta;
        }

       static void Main()
       {
                RenderWindow window = new RenderWindow(new VideoMode(1024, 768), "Mouse Wheel Zoom", Styles.Close);
                window.MouseWheelMoved += new EventHandler<MouseWheelEventArgs>(OnMouseScroll);
                View gameView = new View();

                while (window.IsOpen())
                {
                        window.DispatchEvents();
                        gameView.Zoom(gameZoom);
                        window.SetView(gameView);
                        window.Display();
                        window.Clear();
                }
        }
}
This is a minimized code from my project. I have bolded the parts which are the key elements here. I hope this can provide help for people trying to figure out the magics of mouse wheel handling. I'm going to mark this topic as solved so it will stand out when searching the forums for this.

2
General / Re: Mouse Wheel Scroll Zoom (C# / SFML.Net)
« on: April 26, 2014, 04:42:16 pm »
Yes. I've read through several topics which all state the exact same. No absolute state, got it.
Quote
static void OnMouseScroll(object sender, EventArgs e)
{
    RenderWindow window = (RenderWindow)sender;
    MouseWheelEventArgs mouseEvent = (MouseWheelEventArgs)e;
    if (mouseEvent.Delta.Equals(1))
    {
        gameZoom += 0.01f;
    }
    if (mouseEvent.Delta.Equals(-1))
    {
        gameZoom -= 0.01f;
    }
}
Okay this is me trying to check for events in the mouse wheel. It doesn't work. How can I make it work? The tutorials and documentation are a no-go because there's not a single line of C# code anywhere and example for this kind of feature is nowhere to be found.

Somewhere I got the idea that the mouse wheel has either the value of 1 = up or value of -1 = down. Am I doing it correctly? The code doesn't give out any errors but it doesn't act in anyway either.

3
General / Mouse Wheel Scroll Zoom (C# / SFML.Net) [Solved]
« on: April 26, 2014, 06:13:16 am »
So I'm trying to program a zoom feature with using the mouse scroll. I want to be able to zoom in and out. This is what you see in every day games when you want to change the weapon or when you scroll up and down web pages - so you know what I mean.
Quote
if (Mouse.IsButtonPressed(Mouse.Button.Right))
{
   gameZoom += 0.01f;
}
else if (Mouse.IsButtonPressed(Mouse.Button.Left))
{
   gameZoom -= 0.01f;
}
This is the code that I'm using right now to control the zooming. And it works perfectly just using right and left buttons of the mouse. However it's not as practical as using the mouse wheel to do it. I have looked through the tutorials and tried googling a dozen times for an example with C# and SFML.Net - no such luck...

Please, don't bother giving a another link to the tutorial page. If you have the courtesy to answer, please attach a short C# code which can lead me to my goal. Thank you.

4
General / Re: Problem with FPS-free space physics
« on: March 29, 2014, 01:09:52 am »
Quote
(craft.ThrustActive - craft.ReverseActive * 0.5)

Maybe you have to mulitiply with delta here somehow.

Thanks for the effort but that doesn't seem to do the trick. I've tried dozens of places for the multiplier and none of them did the trick. Should I try to separate the whole thing into smaller expressions or would that even change anything.

Of course the "easy" way would to but a static FPS but it I don't see much honor in that since the systems I've tried the my game with vary a lot with the CPU and GPU capabilities so it's bound to slow down on older systems and with a low frame rate limit it doesn't use my high-end-PC:s resources nearly enough.

Can anyone figure this one out?

5
General / Problem with FPS-free space physics
« on: March 27, 2014, 03:48:44 pm »
I am trying to create a game that would work exactly the same with either 60fps or 2000fps or anything between. Of course high fps as 2000 or even greater is never going to be needed. That is needless to say, so don't bother posting some rant about that subject. That is not what my post is about. But instead, tell me how can I achieve my goal with the following code.
Quote
// Initial values
private float speed = 10f;
private float friction = 0.999f;
private float thrust = 10;
private int turnSpeed = 360;

// Turning a craft
if (Keyboard.IsKeyPressed(Keyboard.Key.Num4)) allCrafts[3].Angle = allCrafts[3].Angle - (allCrafts[3].TurnSpeed * delta);
if (Keyboard.IsKeyPressed(Keyboard.Key.Num6)) allCrafts[3].Angle = allCrafts[3].Angle + (allCrafts[3].TurnSpeed * delta);

// Updating all crafts
foreach (Craft craft in allCrafts)
{
    craft.Momentum_X = (delta * craft.Momentum_X * craft.Friction) + (delta * craft.Thrust * Math.Cos(craft.Angle * (Math.PI / 180.0))) * (craft.ThrustActive - craft.ReverseActive * 0.5);
    craft.Momentum_Y = (delta * craft.Momentum_Y * craft.Friction) - (delta * craft.Thrust * -Math.Sin(craft.Angle * (Math.PI / 180.0))) * (craft.ThrustActive - craft.ReverseActive * 0.5);
               
    craft.X = craft.X + ((float)craft.Momentum_X * craft.Speed * delta);
    craft.Y = craft.Y + ((float)craft.Momentum_Y * craft.Speed * delta);

    craft.Frame = (byte)(craft.Angle/15);

    if (craft.Angle > 360) craft.Angle = 0;
    if (craft.Angle < 0) craft.Angle = 360;

    if (craft.Frame > 23) craft.Frame = 0;
    if (craft.Frame < 0) craft.Frame = 23;

    craft.Shape.TextureRect = new IntRect(0 + (craft.Frame * 64), 0, 64, 64);
    craft.Shape.Position = new Vector2f(craft.X - 25, craft.Y - 25);
    craft.Draw(window);
}

I have no problems with the loop. Everything worked just fine before I added the space physics into the code. The problem here is with the friction, thrust and the momentum factors, I think. For some reason I can't figure out how to use the delta correctly with them. Turning the craft works perfectly fine. Even with 10fps it takes the same time for the craft to turn full circle as with 2000-3000fps, so all fine with that part.

With the current code my craft barely moves since I tried to implement delta in the "craft.Momentum_X =..." -part. If I completely remove delta from there it works about correctly if there is no fps-limit (normally about 2000-3000fps on my system) but of course then if I use something like "window.SetFramerateLimit(60);" it all appears too fast. The craft is about the same speed, but it doesn't accelerate or stop nearly as fast. I get that it's about the fact that I don't multiply those values with delta... but I can't just get my head around it... Help?

Edit: For all it's worth. I am using C# with SFML.Net 2.1.

6
SFML projects / Re: NetEXT - SFML.NET Extension Library based on Thor
« on: March 26, 2014, 07:04:22 pm »
Just a silly question. How do I use it? I have SFML.net installed and fully working but for this one I couldn't find any installation guides. Do I just throw it in there with the SFML-files - and what next? The readme-file was just about the licensing. How about making a step-by-step guide for the newbies :)

Pages: [1]
anything