Hi Ortu...
Thank you for your reply. As to your first question, the answer would be
both (It doesn't recognize that you have clicked or it doesn't recognize what you have clicked on?)
And yes, I have been attempting to use the WinForms Form.MouseDown event to capture the click on the display screen. However, using the AppGameKit GetPointerPressed and GetPointerX functions, I see in both that nothing is returned to either of these functions.
I have been trying to use MadBit's sample "Terrain" project as a guide, which has the the AppGameKit GetPointerPressed and GetPointerX functions within the main "Program.cs" file.
I much prefer VB.NET to C#, though I am fluent in it, so my code snippets are in VB.NET, if you wouldn't mind taking a quick look at them...
My Program.vb
Imports System.Drawing
Imports System.Windows.Forms
Imports AgkSharp
Module MainModule
#Region "Module Level Event Declarations"
Private WithEvents moMoveRightButton As New Button()
#End Region
#Region "Module Level Variable Declarations"
Private msScrollDirection As String = "" ' R=right, L=left, D=down, U=up
#End Region
Sub Main()
' ---
' Variable Declarations
' ---
Dim lboolGameLoopControl As Boolean = True
Dim liX As Integer = 0
Dim liY As Integer = 0
Dim liDirection As Integer = 0
Dim lsnglMouseSelectedX As Single = 0.0
Dim loCore As New Core()
Dim loWindow As New Window()
Dim loForm As New Windows.Forms.Form()
' ---
' Create the initial window\form for the game
' ---
loForm = loWindow.Create_WindowForm(1000, 1000, "My Test WIndow")
' Test the newly created handle for the form object to ensure that it has been created
' * This code will probably not be required for AGK Editor users
If loForm.Handle <> vbNull Then
Agk.InitGL(loForm.Handle)
End If
'AddHandler moMoveRightButton.MouseDown, AddressOf MyButton_MouseDown
AddHandler moMoveRightButton.Click, AddressOf MyButton_Click
moMoveRightButton.Height = 26
moMoveRightButton.Width = 26
moMoveRightButton.BackColor = Color.White
moMoveRightButton.Text = "R"
loForm.Controls.Add(moMoveRightButton)
' ---
' Set the parameters for the display, which are internally related to the newly created
' window\form from the code above
' ---
Agk.SetVirtualResolution(1200, 1200)
Agk.CreateSprite(1, AgkSharp.Agk.LoadImage("Images/HexagonEngineMap.png"))
Agk.SetSpriteSize(1, 2256, 7236)
Agk.SetSpritePosition(1, 0, 0)
Agk.SetSyncRate(0, 0)
Agk.SetScissor(0, 0, 0, 0)
' ---
' Master Game Loop Code
' ...
' Automatically scroll the image in the display area. This scrolling will primarily move the
' image from the top left corner towards the bottom right corner.
'
' ---
While Core.LoopAGK() = True
Agk.SetViewOffset(liX, liY)
Select Case (msScrollDirection)
Case "R" :
liX = liX + 6
End Select
'Get_XLocation()
If (Agk.GetPointerPressed() = 1) Then
lsnglMouseSelectedX = Agk.GetPointerX()
MessageBox.Show(lsnglMouseSelectedX.ToString())
'Agk.Print(lsnglMouseSelectedX.ToString())
End If
Agk.Sync()
End While
Core.CleanUp()
End Sub
Private Sub MyButton_MouseDown(ByVal sender As Object, ByVal loEventArgs As EventArgs)
msScrollDirection = "R"
moMoveRightButton.BackColor = Color.Red
End Sub
Private Sub MyButton_Click(ByVal sender As Object, ByVal loEventArgs As EventArgs)
If (msScrollDirection.Equals("R")) Then
msScrollDirection = ""
moMoveRightButton.BackColor = Color.White
Else
msScrollDirection = "R"
moMoveRightButton.BackColor = Color.Red
End If
End Sub
Private Sub Get_XLocation()
Dim liMouseSelectedX As Integer = 0
If (Agk.GetPointerPressed() <> 0) Then
liMouseSelectedX = Agk.GetPointerX()
MessageBox.Show(liMouseSelectedX)
End If
End Sub
End Module
My Core.vb
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports AgkSharp
Friend Class Core
#Region "Constructor(s)"
Friend Sub New()
End Sub
#End Region
#Region "Class Level Declarations"
Private cboolBreakLoop As Boolean = False
#End Region
#Region "Friend Methods"
Friend Shared Function LoopAGK() As Boolean
Application.DoEvents()
'If (Agk.IsCapturingImage()) > 0 Then
System.Threading.Thread.Sleep(10)
'End If
Return (True)
End Function
Friend Shared Sub CleanUp()
Agk.CleanUp()
End Sub
#End Region
End Class
My Window.vb
Imports System.Drawing
Imports System.Windows.Forms
Imports AgkSharp
Friend Class Window
#Region "Class Level Event Declarations"
'Private WithEvents coWindowsForm As New Windows.Forms.Form()
#End Region
#Region "Constructor(s)"
Friend Sub New()
End Sub
#End Region
#Region "Friend Methods"
Friend Sub Initialze_Window(ByVal piWidth As Integer,
ByVal piHeight As Integer,
ByVal psWindowTitle As String,
ByVal piClearColorR As Integer,
ByVal piClearColorG As Integer,
ByVal piClearColorB As Integer)
' set the window's dimensions
If (piWidth.Equals(0) And piHeight.Equals(0)) Then
AgkSharp.Agk.SetWindowSize(0, 0, 1)
Else
AgkSharp.Agk.SetWindowSize(piWidth, piHeight, 0)
End If
' set the window's title
AgkSharp.Agk.SetWindowTitle(psWindowTitle)
' set the aspect ration
AgkSharp.Agk.SetDisplayAspect(1.0 * piWidth / piHeight)
' clear the screen to initial color
AgkSharp.Agk.SetClearColor(piClearColorR, piClearColorG, piClearColorB)
AgkSharp.Agk.ClearScreen()
' use vector fonts
AgkSharp.Agk.UseNewDefaultFonts(1)
End Sub
Friend Function Create_WindowForm(ByVal piWidth As Integer,
ByVal piHeight As Integer,
ByVal psWindowTitle As String) As Windows.Forms.Form
Dim loForm As New Windows.Forms.Form()
AddHandler loForm.MouseDown, AddressOf Form_OnMouseDown
AddHandler loForm.MouseUp, AddressOf Form_OnMouseUp
loForm.ClientSize = New Size(piWidth, piHeight)
loForm.Text = psWindowTitle
loForm.StartPosition = Windows.Forms.FormStartPosition.CenterScreen
If (piWidth.Equals(0) And piHeight.Equals(0)) Then
loForm.WindowState = Windows.Forms.FormWindowState.Normal
loForm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
loForm.Bounds = Windows.Forms.Screen.PrimaryScreen.Bounds
End If
loForm.Show()
Return (loForm)
End Function
#End Region
Private Sub Form_OnMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim lsnglMouseSelectedX As Single = 0.0
If e.Button = MouseButtons.Left Then
Agk.MouseLeftButton(0, 1)
End If
If e.Button = MouseButtons.Right Then
Agk.MouseRightButton(0, 1)
End If
If e.Button = MouseButtons.Middle Then
Agk.MouseMiddleButton(0, 1)
End If
End Sub
Private Sub Form_OnMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
If e.Button = MouseButtons.Left Then
Agk.MouseLeftButton(0, 0)
End If
If e.Button = MouseButtons.Right Then
Agk.MouseRightButton(0, 0)
End If
If e.Button = MouseButtons.Middle Then
Agk.MouseMiddleButton(0, 0)
End If
End Sub
End Class
Thank you for your help. It is greatly appreciated...
Steve Naidamast
Sr. Software Engineer