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

Author Topic: I have the following program, can someone please answer a couple of questions?  (Read 3377 times)

0 Members and 2 Guests are viewing this topic.

microchip

  • Guest
Hi, I have the following program and it works fine. I have a couple of questions because I'm not an expert at this.

If you run the program (I attached the images), you will see that it moves faster to the left than to the right. I did that on purpose. My first question is -> If you look close, the motion kind of stutters or there are tiny steps where it jumps. Would this be super smooth if I implement Frame Independent movement?
My second question is -> Can someone show me an example of how I can use a sprite sheet. I would like to make the character walk to the left and right.

Bonus question -> Where can I find info on frame independent movement in VB .net - C++ code is ok with me too, but .NET uses different timing devices, so I'm not sure where to start.

Don't forget to change the file paths.

Imports SFML
Imports SFML.Window
Imports SFML.Graphics
Imports System.Drawing

Module Module1
    Dim WithEvents window As RenderWindow

    Sub Main()
        Dim contextSettings As New ContextSettings
        contextSettings.DepthBits = 32

        window = New RenderWindow(New VideoMode(800, 600), "Learning SFML", Styles.Default, contextSettings)
        window.SetVerticalSyncEnabled(True)

        Dim myTexture As New Texture("c:\pics\bg.png")
        Dim myTexture2 As New Texture("c:\pics\char123.gif")
        Dim mySprite As New Sprite
        Dim mySprite2 As New Sprite

        mySprite.Texture = myTexture
        mySprite2.Texture = myTexture2

        Dim b As Boolean = False

        Dim r As New Single
        r = 0.1F

        mySprite2.Origin = New Vector2f(myTexture2.Size.X / 2, myTexture2.Size.Y / 2)

        Dim n As Integer = 100

        While window.IsOpen
            window.DispatchEvents()
            window.Clear()

            mySprite.Position = New Vector2f(0, 0)
            mySprite2.Position = New Vector2f(n, 320)
            mySprite2.Rotation = r

            window.Draw(mySprite)

            r += 0.5

            If b = False Then
                n += 2
            Else
                n -= 1
            End If
            If n = 50 Then b = False
            If n = 750 Then b = True

            window.Draw(mySprite2)

            window.Display()
        End While
    End Sub

    Sub App_Closed(sender As Object, e As EventArgs) Handles window.Closed
        Dim window = CType(sender, RenderWindow)
        window.Close()
    End Sub
End Module
 
« Last Edit: December 31, 2014, 08:49:37 pm by microchip »

rcurtis

  • Newbie
  • *
  • Posts: 19
    • View Profile
SFML specific spritesheet tutorial from Laurent:  https://github.com/SFML/SFML/wiki/Source:-Sprite-Sheets

SFML specific time based movement discussion: http://stackoverflow.com/questions/18306101/movement-without-framerate-limit-c-sfml

I would urge you to do a basic google search on these topics before posting here.  This community is very helpful, but failing to do even a cursory look for answers on your own won't get you very far.  Good luck!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
SFML specific spritesheet tutorial from Laurent:  https://github.com/SFML/SFML/wiki/Source:-Sprite-Sheets
It's on the wiki and the wiki is for everyone, so no it's not written by Laurent.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/