Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I have two classes, like these:

 

Class MainClass
   Inherits SubClass

   Private NewClass as SubClass

   Public Function Test()
       NewClass = new SubClass

       Messagebox.show("TestBox :p")
       NewClass.DoSomething()
   End Function

   Public Overrides SubFunction()
       Messagebox.show("Yup it works!!")
   End Function
End Class

Class SubClass
   Public Function DoSomething()
       'Do something
       SubFunction
       'Do something
   End Function

   Public Overridable Function SubFunction()
       'Should be overwritten
   End Function
End Class

 

But only the first messagebox appears... What am i doing wrong? I get no errors or anything..

Edited by Loffen
Erutangis a si tahw
  • Administrators
Posted

Just looking at your code - what did you expect to happen? Haven't got VS installed here so I can't step through it and it looks a bit convaluted to follow through by hand.

It should display a message box saying "TestBox :p" - is that happening?

In the line

SubClass.DoWhatever()

did you mean

newClass.DoWhatever()

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)
did you mean

newClass.DoWhatever()

Err... Yeah i did mean that... *Fixed*

 

Actually this is a part of my game made with DirectX, Where SubFunction is the Render() function... Posting the class again whith changes... Hope it get clearer then...

 

[color=Blue]Class[/color] GameEngine
   [color=Blue]Inherits[/color] GraphicsEngine

   [color=Blue]Private[/color] Graphics [color=Blue]as[/color] GraphicsEngine

   [color=Green]'This is called from form1..[/color]
   [color=Blue]Public Function[/color] Init()
       Graphics = [color=Blue]new[/color] GraphicsEngine

       Messagebox.show("Init Success")
       Graphics.RenderLoop()
   [color=Blue]End Function[/color]

   [color=Blue]Public Overrides Function[/color] Render()
       Messagebox.show("In overrides Render()")
   [color=Blue]End Function
End Class[/color]

[color=Blue]Class[/color] GraphicsEngine
   [color=Blue]Public Function[/color] RenderLoop()
       Device.Clear()
       DeviceBeginScene()

       Render()

       Device.EndScene()
       Device.Present()
   [color=Blue]End Function[/color]

   [color=Blue]Public Overridable Function[/color] Render()
       [color=Green]'Should be overwritten[/color]
   [color=Blue]End Function
End Class[/color]

Edited by Loffen
Erutangis a si tahw
Posted

Neee.... not 100% sure what you mean?? I want to run the code inside: Public Overrides Function Render(). The overwritten function is only there so my Graphics Class knows what function to call uring rendering. And as the object rendered are different from game to game. Later i probably will put the whole Graphics class into a dll, thets why i need the function so the 'caller' can render whatever the 'caller' wants

 

Public Overridable Function Render()

'Should be overwritten. Nothing inside here sould be executed, only inside the other Render()

End Function

 

Public Overrides Function Render()

Messagebox.show("In overrides Render()")

'Here the code sould be executed...

End Function

 

!! It wont let me place MyBase.Render() inside Public Overridable Function Render()

Erutangis a si tahw
  • Administrators
Posted

Sorry - mis-understood your problem.

 

In your init method you are declaring a variable of type GraphicsEngine - so when you call render you will get the GraphicsEngine version of the function.

 

What you need to do is declare a variable of type GameEngine:

   Public Function Init()
       Graphics = New GameEngine

       Messagebox.show("Init Success")
       Graphics.RenderLoop()
   End Function

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Didnt understand that 100% ether? Ill post my GameEngine Class... The code i am talking about is almost at the bottom..

 

[color=Blue]Imports[/color] Microsoft.DirectX
[color=Blue]Imports[/color] Microsoft.DirectX.Direct3D
[color=Blue]Imports[/color] Microsoft.DirectX.Direct3D.D3DX
[color=Blue]Imports[/color] System.Math

[color=Blue]Public Class[/color] GameEngine
   [color=Blue]Inherits[/color] GraphicsEngine

   [color=Blue]Public[/color] Graphics [color=Blue]As[/color] GraphicsEngine

   [color=Blue]Public Function[/color] Init([color=Blue]ByVal[/color] Target [color=Blue]As[/color] System.Windows.Forms.Form)
       Graphics = [color=Blue]New[/color] GraphicsEngine

       Graphics.BackBufferWidth = 800
       Graphics.BackBufferHeight = 600
       Graphics.BackBufferFormat = Format.A8R8G8B8
       Graphics.BackBufferCount = 1

       Graphics.SwapEffect = SwapEffect.Copy
       Graphics.PresentInterval = PresentInterval.One
       Graphics.CreateFlags = CreateFlags.HardwareVertexProcessing [color=Blue]Or[/color] CreateFlags.MultiThreaded
       Graphics.DeviceType = DeviceType.Hardware

       Graphics.GraphicsTarget = Target

       Graphics.GraphicsInitDevice()

       [color=Green]'This is the map object[/color]
       Graphics.Map = [color=Blue]New[/color] GraphicsMap
       Graphics.Map.LoadMap(Graphics.Device, "testmap")

       Graphics.Player = [color=Blue]New[/color] GraphicsSprite(Graphics.Device, Application.StartupPath & "\objects\human1\human1.bmp", New Point(0, 0), 16, 16, &HFF00FF00)

       [color=Green]'//--------------------------------------------------
       '// Different font types
       '//--------------------------------------------------[/color]
       Graphics.MessageText = [color=Blue]New[/color] GraphicsText(Graphics.Device, "Verdana", 8, FontStyle.Bold)
       Graphics.MissionText = [color=Blue]New[/color] GraphicsText(Graphics.Device, "Verdana", 18)
       Graphics.HUDText = [color=Blue]New[/color] GraphicsText(Graphics.Device, "Verdana", 22, FontStyle.Bold)

       [color=Blue]While[/color] Graphics.GraphicsRunning = [color=Blue]True[/color]
           [color=Green]'This is the function wich again calls the Overridable Render() function..[/color]
[color=Red][b] !! HERE !![/b][/color]
           Graphics.GraphicsRenderLoop()

           Application.DoEvents()
       [color=Blue]End While[/color]

       Graphics.Player.Destroy()
       Graphics.Map.DestroyMap()

[color=Blue]        End
   End Function

[color=Red][b]!! AND HERE !![/b][/color]
   Public Overrides Function[/color] Render()
       [color=Green]'The message box wont pop up...[/color]
       MessageBox.Show("Inside the correct render function!!")
       [color=Blue]End[/color]
   [color=Blue]End Function

End Class[/color]

Erutangis a si tahw
  • Administrators
Posted

At the top you have

Public Class GameEngine
   Inherits GraphicsEngine

   Public Graphics As GraphicsEngine

this means you are declaring a variable called Graphics of type GraphicsEngine

 

later on you have

While Graphics.GraphicsRunning = True
           'This is the function wich again calls the Overridable Render() function..
           Graphics.GraphicsRenderLoop()

           Application.DoEvents()
       End While

in this code you are calling the GraphicsRenderLoop method of the Graphics object, within the Graphics object's GraphicsRenderLoop you are making a call to a Render method - because the variable Graphics was declared as type GraphicsEngine you get the GraphicsEngine's version of this method.

 

If you want to call the overridden method declared in the GameEngine class then you need to declare a variable of Type GameEngine.

 

However because your GameEngine class inherits from GraphicsEngine you do not need to declare a variable to access the GraphicsEngine's functionality.

 

You should be able to declare the code within the GameEngine like

Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX.Direct3D.D3DX
Imports System.Math

Public Class GameEngine
   Inherits GraphicsEngine

   Public Function Init(ByVal Target As System.Windows.Forms.Form)
       BackBufferWidth = 800
       BackBufferHeight = 600
       BackBufferFormat = Format.A8R8G8B8
       BackBufferCount = 1

       SwapEffect = SwapEffect.Copy
       PresentInterval = PresentInterval.One
       CreateFlags = CreateFlags.HardwareVertexProcessing Or CreateFlags.MultiThreaded
       DeviceType = DeviceType.Hardware

       GraphicsTarget = Target

       GraphicsInitDevice()

       'This is the map object
       Map = New GraphicsMap
       Map.LoadMap(Device, "testmap")

       Player = New GraphicsSprite(Device, Application.StartupPath & "\objects\human1\human1.bmp", New Point(0, 0), 16, 16, &HFF00FF00)

       '//--------------------------------------------------
       '// Different font types
       '//--------------------------------------------------
       MessageText = New GraphicsText(Device, "Verdana", 8, FontStyle.Bold)
       MissionText = New GraphicsText(Device, "Verdana", 18)
       HUDText = New GraphicsText(Device, "Verdana", 22, FontStyle.Bold)

       While GraphicsRunning = True
           'This is the function wich again calls the Overridable Render() function..
           GraphicsRenderLoop()

           Application.DoEvents()
       End While

       Player.Destroy()
       Map.DestroyMap()

       End
   End Function

   Public Overrides Function Render()
       'The message box wont pop up...
       MessageBox.Show("Inside the correct render function!!")
       End
   End Function

End Class

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...