Can anyone tell me why I get a memory unhandled exception when clicking the mouse 1 button please.
(Includes are built automatically as I am using Blide Plus so they are not coded directly)
main.bmx
Graphics(1280, 800, 32, 60)
SeedRnd MilliSecs() 'used for random number generator
Local timer:TTimer = CreateTimer(60) '60hz timer
Local fps:Int = 0
Local fpscounter:Int=0
Local fpstimer:Int=MilliSecs()
Local c:Int
While Not KeyHit(KEY_ESCAPE)
Cls
If MouseHit(1)
'create a shape
ShapeObject.Create(Rnd(1280), Rnd(800), Rnd(50), Rnd(100))
End If
c = ShapeList.Count()
DrawText("count: " + c, 0, 0)
'if shape list is not empty then update the shapes
If c > 0 Then ShapeObject.Update
'fpstimer update
'#Region
If MilliSecs() > fpstimer + 1000
fps = fpscounter
fpscounter = 0
fpstimer = MilliSecs()
Else
fpscounter = fpscounter + 1
End If
DrawText ("FPS: " + fps, 0, 20)
'#End Region
Flip
WaitTimer (timer)
Wend
declarations.bmx
Rem
Date: 6/11/08
Description: Global declarations
End Rem
Global ShapeObject:TShape 'object identifier for the shape, used to reference each shape object
Global ShapeList:TList = CreateList()
shape.bmx
Rem
Date: 6/11/08
Description: Type class for the shape objects
End Rem
Type TShape
Field x:Int 'x position of the shape on the screen
Field y:Int 'y position of the shape on the screen
Field h:Int 'height in pixels of shape
Field w:Int 'width in pixels of shape
'======================================================================================================
'
'Method : Create
'Description : Creates a new shape and adds it to the list
'
'======================================================================================================
Function Create:TShape(nx:Int, ny:Int, nw:Int, nh:Int)
ShapeObject:TShape = New TShape
ShapeObject.x = nx 'add the x
ShapeObject.y = ny 'add the y
ShapeObject.h = nh 'add height
ShapeObject.w = nw 'add width
ShapeList.AddLast(ShapeObject)' this object to the list for tracking
Return ShapeObject
End Function
'======================================================================================================
'
'Method : Draw
'Description : Displays shape at x,y, called in the update method
'
'======================================================================================================
Method Draw()
DrawRect(ShapeObject.x, ShapeObject.y, ShapeObject.w, ShapeObject.h)
End Method
'======================================================================================================
'
'Method : Update
'Description : Perform draw and move methods
'
'======================================================================================================
Method Update()
Local s:TShape
'update each shape in the list
For s:TShape = EachIn ShapeList
s.Draw 'draw the shape on the screen
Next
End Method
'======================================================================================================
'======================================================================================================
'
'Method : Delete
'Description : Deletes all shapes in the list
'
'======================================================================================================
Method Del()
Local s:TShape
For s:TShape = EachIn ShapeList
ShapeList.Remove s
Next
End Method
'======================================================================================================
End Type
|