Slowdowns by 2D Game and ~ 300 FPS ??!!!!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
SAS
Posts: 5
Joined: Fri Feb 29, 2008 11:20 am

Slowdowns by 2D Game and ~ 300 FPS ??!!!!

Post by SAS »

Hi iam new :)
Sorry for my Bad English.. iam German ;9




So my Problem is that i whil create a 2D Game (Break Out Clone) and i have Slowdowns in the Movement ...?? I dont no what that is i have on my Computer ~ 300 FPS and the Game runs great.. only that the Movement is not Smooth.. looks like Slowdows:

I Programming with VB.NET
And the Movement is calculated with the Timerfunction.
Please can anyone me Help with my Problem ?! so i can finish my first Game with Irrlicht.

I Upload my Game (Is not Finish (Without Menu ad only one Level)



Thanks
SAS

http://rapidshare.com/files/95865554/Br ... e.rar.html
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

do you mean when you try and change the direction the player's platform is moving in?

That's due to bad event receiver code when handling the key presses.

I didn't notice any other slow downs at all...
Image Image Image
SAS
Posts: 5
Joined: Fri Feb 29, 2008 11:20 am

Post by SAS »

JP wrote:do you mean when you try and change the direction the player's platform is moving in?

That's due to bad event receiver code when handling the key presses.

I didn't notice any other slow downs at all...
NoNo is not Only by the Events.. I Move the Ball in a Loop and for the Ball i need no Eventreceiver.. and that is the same Problem like the Images what i move with keys...
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yeah i see what you mean now... The platform actually moves fine most of the time but sometimes messes up so i guess the event receiver is fine...

Well i guess just post the code for the movement of the ball and platform and we'll see if we can spot any errors.

Nice job btw, it looks very nice!
Image Image Image
SAS
Posts: 5
Joined: Fri Feb 29, 2008 11:20 am

Post by SAS »

Thanks ;)
and Thanks for your help
so thats the needed Code.

I Write all in Classes.

In my Imageclass is a Function for Updating:

Code: Select all

 
Public Sub Updateting()
            Dim multi = deltatime
            spritepos.X += myvelX * multi
            spritepos.Y += myvely * multi


            Engine.VideoDriver.Draw2DImage(spriteimage, spritepos, SpriteRECT, MYRGB, True)
            myREct.Width = SpriteRECT.Width
            myREct.Height = SpriteRECT.Height
            myREct.X = spritepos.X
            myREct.Y = spritepos.Y
        End Sub
The myREct is the Rectangle for Collision.

and then in the RenderLoop

Code: Select all


While Engine.Run = True

            If Engine.WindowActive Then

                Dim ccolor As Drawing.Color = backcolor
                Engine.VideoDriver.BeginScene(True, True, New Color(0, ccolor.R, ccolor.G, ccolor.B))
                ' Alle Sprites Zeichnen

                For Each item As PE2D.Image In Imageslist
                    If item.Visible = True Then
                        item.Updateting()
                    End If
                Next


                ' Alle Animations Sprites Zeichnen
                Dim tmplist As New ArrayList(Animationlist)
                For Each item As PE2D.Animation In tmplist
                    If item.Visible = True Then
                        item.Updateting()
                        If item.Visible = False Then
                            Animationlist.Remove(item)
                        End If
                    End If
                Next


                ' Alle Texte Zeichnen
                For Each item As PE2D.Text In Textlist
                    item.Updateting()
                Next


                ' Cursor zeichnen
                If IsCur = True Then
                    Engine.VideoDriver.Draw2DImage(Cur, Engine.CursorControl.Position, currect, New Video.Color(255, 255, 255, 255), True)
                End If


                Form1.MyEvents()
                Engine.SceneManager.DrawAll()
                Guienf.DrawAll()
                Engine.VideoDriver.EndScene()


                Engine.WindowCaption = "2D TEST | Renderzeit : " & deltatime & " | FPS :" & Engine.VideoDriver.FPS.ToString
            End If

            deltatime = Engine.Timer.Time - m_time
            m_time += deltatime
        End While

        Form1.Close()
All Images are saved in the Imageslist Array


ANd the Function Form1.MyEvents is the Function for the Keys
The Eventreceiver save the Keydown key in the key Variable

Code: Select all

If game_running = True Then
            If PE2D.deltatime <> 0 Then
                If _2dengine.Key = KEY_LEFT Then
                    balk_v_X = 1
                    Dim mycoll As PE2D.Image = Balken.Collision

                    If mycoll.Name <> "Nothing" Then
                        If mycoll.Name = "rand_l" Then
                            'Balken.Velocity = New Drawing.Point(0, 0)
                            Balken.Velocity_X = 0.0
                            Balken.Velocity_Y = 0.0
                        Else
                            'Balken.Velocity = New Drawing.Point(-3, 0)
                            Balken.Velocity_X = -balkspeed
                        End If
                    End If

                    Else
                        If _2dengine.Key = KEY_RIGHT Then
                            Dim mycoll As PE2D.Image = Balken.Collision
                        balk_v_X = 2

                        If mycoll.Name <> "Nothing" Then
                            If mycoll.Name = "rand_r" Then
                                'Balken.Velocity = New Drawing.Point(0, 0)
                                Balken.Velocity_X = 0.0
                            Else
                                If mycoll.Name = "ball" Then
                                    balk_v_X = 2
                                End If
                                'Balken.Velocity = New Drawing.Point(+3, 0)
                                Balken.Velocity_X = balkspeed
                            End If
                        End If

                        Else
                        ' Balken.Velocity = New Drawing.Point(0, 0)
                        Balken.Velocity_X = 0.0
                        End If
                    End If

                    If _2dengine.Key = KEY_ESCAPE Then
                        Me.Close()
                    End If




                    ' Ballbewegung
                    If Move_Ball = True Then
                        If Ball.Position.Y < Me.Height Then
                            Dim mycoll As PE2D.Image = Ball.Collision

                        If mycoll.Name = "balken" Then
                            If Slowmo = True Then
                                If Slowmo_hits = 3 Then
                                    bspeed = 0.3
                                    Ball.RGB = Drawing.Color.White
                                    Slowmo = False
                                Else
                                    Slowmo_hits = Slowmo_hits + 1
                                End If
                            End If

                            If sball = True Then
                                If sball_hits = 3 Then
                                    bspeed = 0.3
                                    Ball.RGB = Drawing.Color.White
                                    sball = False
                                Else
                                    sball_hits = sball_hits + 1
                                End If
                            End If

                            If last_stones - lvl_Stones > 10 Then
                                ' MsgBox("YEA") 

                            End If
                            last_stones = lvl_Stones

                            B_Move_Y = -bspeed
                            sound_Balk.Play()
                            If balk_v_X = 1 Then
                                B_Move_x = +bspeed
                            End If

                            If balk_v_X = 2 Then
                                B_Move_x = -bspeed
                            End If

                        End If

                            If mycoll.Name = "rand_o" Then
                            sound_Crash.Play()
                            B_Move_Y = +bspeed
                            End If

                            If mycoll.Name = "rand_l" Then
                            sound_Crash.Play()
                            B_Move_x = +bspeed
                            End If

                            If mycoll.Name = "rand_r" Then
                            sound_Crash.Play()
                            B_Move_x = -bspeed
                            End If

                            ' Blockkollisionen
                            If mycoll.Name = "rot" Or mycoll.Name = "blau" Or mycoll.Name = "gelb" Or mycoll.Name = "grün" Then

                            ' Bonussystem
                            Dim Bonus As New Random(Environment.TickCount)
                            Dim Bonusit = Bonus.Next(30)
                            Check_Bonus(Bonusit, mycoll)
                            '________________________________|

                            lvl_Stones = lvl_Stones - 1
                            ' Partikel erzeugen
                            If _2dengine.Current_Animations < 5 Then
                                Dim p = New PE2D.Animation
                                p.Animation_Speed = 0
                                p.isLoop = False
                                p.RemoveAtEnd = True
                                p.AddImage(myIMages & "Particle_spray_04.png", 128, 7, 8, 56, Ball.Position.X - 64, Ball.Position.Y - 64)
                            End If

                            sound_Block.Play()
                            Dim n As String = mycoll.Name

                            mycoll.Visible = False
                            mycoll.Collision_Detect = False
                            If n = "rot" Then
                                Player_Points = Player_Points + 5
                                totalscore = totalscore + 5
                                score_txt.Changetext(Player_Points)
                                totscore_txt.Changetext(totalscore)
                            Else
                                If n = "blau" Then
                                    Player_Points = Player_Points + 10
                                    totalscore = totalscore + 10
                                    score_txt.Changetext(Player_Points)
                                    totscore_txt.Changetext(totalscore)
                                Else
                                    If n = "grün" Then
                                        Player_Points = Player_Points + 15
                                        totalscore = totalscore + 15
                                        score_txt.Changetext(Player_Points)
                                        totscore_txt.Changetext(totalscore)
                                    Else
                                        If n = "gelb" Then
                                            Player_Points = Player_Points + 20
                                            totalscore = totalscore + 20
                                            score_txt.Changetext(Player_Points)
                                            totscore_txt.Changetext(totalscore)
                                        End If
                                    End If
                                End If
                                mycoll.Remove()
                            End If

                            If B_Move_Y = +bspeed Then
                                B_Move_Y = -bspeed
                            Else
                                B_Move_Y = +bspeed
                            End If

                            ' Zufällige abbrallrichtung
                            Dim x As New Random(Environment.TickCount)
                            Dim nx = x.Next(2)
                            If nx = 1 Then
                                B_Move_x = -bspeed
                            Else
                                B_Move_x = +bspeed
                            End If
                        End If

                        'Ball.Velocity = New Drawing.Point(B_Move_x, B_Move_Y)
                        Ball.Velocity_X = B_Move_x
                        Ball.Velocity_Y = B_Move_Y
                        Else
                        ' Leben Abziehen
                        If lifes > 0 Then
                            lifes = lifes - 1
                            Dim it As PE2D.Image = lifes_li.Item(lifes_li.Count - 1)

                            it.ChangeImage("minus_life")
                            lifes_li.RemoveAt(lifes_li.Count - 1)
                            B_Move_Y = +bspeed
                            B_Move_x = 0

                            Ball.RGB = Drawing.Color.White
                            bspeed = 0.3
                            Balken.ChangeImage("Balken_normal")
                            Ball.Position = New Drawing.Point(Balken.Position.X + (Balken.Size.Width / 2), Balken.Position.Y - 150)

                        Else
                            MsgBox("Hier ist man Game Over! Function zum Menüaufrufen... : " & lifes)
                            Me.Close()
                        End If
                    End If

                    End If
                End If
                stime = My.Computer.Clock.LocalTime.TimeOfDay.Subtract(time)
                time_txt.Changetext(stime.Minutes & ":" & stime.Seconds)

                If stime.Seconds = 60 Then
                    Player_Points = Player_Points - 5
                    score_txt.Changetext(Player_Points)
                End If
        End If

        Dim tmplist As New ArrayList(Bonuslist)
        ' Bonusbewegung
        For Each item As PE2D.Image In tmplist
            'item.Velocity = New Drawing.Point(0, +1)
            item.Velocity_Y = 0.2

            If item.Position.Y < Me.Height Then
                Dim coll As PE2D.Image = item.Collision
                If coll.Name = "balken" Then
                    ' Bonus anwenden
                    If item.Name = "Bonus_1" Then
                        ' Langer Balken
                        Bonuslist.Remove(item)
                        item.Visible = False
                        item.Remove()
                        Balken.ChangeImage("Balken_Lang")
                    End If

                    If item.Name = "Bonus_2" Then
                        ' Kurzer Balken
                        Bonuslist.Remove(item)
                        item.Visible = False
                        item.Remove()
                        Balken.ChangeImage("Balken_kurz")
                    End If

                    If item.Name = "Bonus_3" Then
                        ' Speed Ball
                        Bonuslist.Remove(item)
                        item.Visible = False
                        item.Remove()
                        Ball.RGB = Drawing.Color.Red
                        bspeed = 0.5
                        sball = True
                        Slowmo = False
                        sball_hits = 0
                    End If

                    If item.Name = "Bonus_4" Then
                        ' Slow Motion
                        Bonuslist.Remove(item)
                        item.Visible = False
                        item.Remove()
                        Ball.RGB = Drawing.Color.Blue
                        bspeed = 0.1
                        Slowmo_hits = 0
                        Slowmo = True
                        sball = False
                    End If

                    If item.Name = "Bonus_5" Then
                        ' + 300 Punkte
                        Bonuslist.Remove(item)
                        item.Visible = False
                        item.Remove()
                        Player_Points = Player_Points + 300
                        totalscore = totalscore + 300
                        score_txt.Changetext(Player_Points)
                        totscore_txt.Changetext(totalscore)
                    End If

                    If item.Name = "Bonus_6" Then
                        ' + 500 Punkte
                        Bonuslist.Remove(item)
                        item.Visible = False
                        item.Remove()
                        Player_Points = Player_Points + 500
                        totalscore = totalscore + 500
                        score_txt.Changetext(Player_Points)
                        totscore_txt.Changetext(totalscore)
                    End If

                    If item.Name = "Bonus_7" Then
                        ' + 1 Leben
                        Bonuslist.Remove(item)
                        item.Visible = False
                        item.Remove()
                        If lifes < 6 Then
                            Dim Lif As PE2D.Image = total_lifes.Item(lifes)
                            Lif.ChangeImage("Ball_green")
                            lifes = lifes + 1
                            lifes_li.Add(Lif)
                        End If
                    End If

                End If
            Else
                Bonuslist.Remove(item)
                item.Visible = False
                item.Remove()
            End If
        Next

Sorry for the Long code.
I Hope thats help.
SAS
Posts: 5
Joined: Fri Feb 29, 2008 11:20 am

Post by SAS »

Please can anyone help me ?!!!
I Need Help..

Sorry taht i push it up
Post Reply