MouseOver Entity

From Blue Mars Developer Guidebook

Jump to: navigation, search

Overview

This script shows how you can detect mouseover enter and exit over entities.

Usage

  1. Install this entity class
  2. edit the OnMouseEnter and OnMouseExit with the behavior you want (apply a highlight material, play a sound, popup text or HUD display...)
  3. drag an instance of this entity into your scene and invoke the Start functon (e.g. with a trigger)
  4. remove debug messages if you want (probably after you make sure it works)

As with other uses of ARMousePickEntity and similar functions, test it in the Blue Mars client, as the raycast results are off with respect to the screen in the Editor.

Code

MouseOverEntity = {
   currentEntity, -- save the current moused over entity
}

function MouseOverEntity:Start()
   ARDebug(3)
   ARDebugMessage("mouseover active!")
   self:Activate(1) -- make sure OnUpdate is called
end

function MouseOverEntity:OnUpdate(deltaTime)
   local entity = ARMousePickEntity()
   if (entity ~= self.currentEntity) then
      if self.currentEntity then
	 self:OnMouseExit()
      end
      self.currentEntity = entity
      if self.currentEntity then
	 self:OnMouseEnter()
      end
   end
end

function MouseOverEntity:OnMouseEnter()
	 ARDebugMessage("Entering "..self.currentEntity:GetName())
	 -- apply your mouseover behavior with currentEntity
      end

function MouseOverEntity:OnMouseExit()
	 ARDebugMessage("Exiting "..self.currentEntity:GetName())
	 -- cleanup any mouseover behavior with currentEntity
end
Problems with this wiki page? Contact us either by: Support Email or Support Ticket System

Blue Mars Guidebook Privacy Policy
Blue Mars Guidebook Community Guidelines

Personal tools