November 16, 2018 at 7:09 am #15607
I was writing a little framework designed to go “on top” of mojo3d, but things were getting unwieldy and I decided to break it apart into as many separate, simple independent modules as possible.
The first one is a barebones “GuiComponent” class that can handle mouse events like “OnMouseOver”, “OnMouseEnter”, “OnMouseClick( mousebutton )”, etc. The class is abstract, intended to alway be extended. Example:Monkey1234567891011121314151617181920212223242526272829303132333435363738Class MouseTest Extends GuiComponentGlobal camera:CameraMethod New( e:Entity )Super.New( e )EndMethod OnMouseEnter() OverrideEntity.Color = Color.BlackEndMethod OnMouseLeave() OverrideEntity.Color = Color.WhiteEndMethod OnMouseClick( button:MouseButton ) OverrideSelect buttonCase MouseButton.Left Print "Left button clicked on " + Entity.NameCase MouseButton.Middle Print "Middle button clicked on " + Entity.NameCase MouseButton.Right Print "Right button clicked on " + Entity.NameEndEndMethod OnMouseRelease( button:MouseButton ) OverrideSelect buttonCase MouseButton.Left Print "Left button released on " + Entity.NameCase MouseButton.Middle Print "Middle button released on " + Entity.NameCase MouseButton.Right Print "Right button released on " + Entity.NameEndEndMethod OnDraw( canvas:Canvas ) OverrideLocal pos := camera.ProjectToViewport( Entity.Position )canvas.DrawText( Entity.Name, pos.X, pos.Y )EndEnd
For it to work, there are a couple extensions for the Scene and Canvas classes that need to be called:Monkey12scene.UpdateGui3D( camera, Mouse.Location )canvas.DrawGui3D( scene )
There’s an example in the “_tests” folder:
I hope to add some more useful methods in the future.
Cheers!November 16, 2018 at 8:27 am #15608
Cool, I’ll hopefully get to try tonight or tomorrow.November 22, 2018 at 7:49 am #15611
Updated it, and now in addition to GuiComponents it has an early, largely untested class called GameComponents. It provides collision events like OnCollisionEnter( body ) , OnCollisionStay( body ) and OnCollisionLeave( body ). You need to use the “GameBody” class instead of the regular “RigidBody” to achieve that.
There’s even a… uhh… bananas demo! 🙂 It showcases a simple GameComponent:Monkey123456789101112131415Class CollisionColor Extends GameComponentMethod New( e:Entity )Super.New( e )EndMethod OnCollisionEnter( body:RigidBody ) OverrideEntity.Color = Color.RedEndMethod OnCollisionLeave( body:RigidBody ) OverrideEntity.Color = Color.WhiteEndEnd
And here it is in action:
The repo was renamed GameComponents to reflect the changes. Will probably post it in the Code Library section once I’ve tested it some more. Will also include an “Arcade Physics” style Character Controller (based on Mark’s QCollide demo) that uses the exact same Collision Events as the physics system. Take that, Unity3D!
You must be logged in to reply to this topic.