Technology Demo

Auto Mouse Picking Demo

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Spot for images

Intro

This demo will show you how to enable automatic mouse picking, so that events will be sent whenever the mouse hits an object.

Mouse Picking

Automatic mouse picking is the simplest to write, but also decreases the performance, as every time the mouse moves a ray is sent out to see if it's over any object in the scene. To enable automatic mouse picking, simply add the following line to your project.

self.autoPicking = true

To see what our new mouse picking can do, let's create a cube.

self.cube = luster.display.Entity(luster.resources.Mesh.CUBE)
self:addChild(self.cube)
self.cube.scale=0.01
self.cube.mouseEnabled = true
self.cube:addEventListener(luster.display.DisplayObject.MOUSE_OVER, Function(self, self.onMouseOver))

In order to interact with the cube, the cube's mouseEnabled boolean must be set to true. The event can then be attached to the cube.

function Root:onMouseOver()
trace("hit")
end

The onMouseOver function will just print out "hit" to the console whenever the cube is moused over.