Log In  


Cart #51485 | 2018-04-10 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

This is a simple mouse over text detection example.
Made it to help someone else's question but figured I'd post it here.

Also this isn't optimized, I tried to make it more for learning than optimization.
For instance:

function _mot(_t) 
--if mouse is within the text
-- boundaries then set that 
-- text.over to equal true
 if(_mx>=_t.x and _mx<(_t.x+(#_t.str*4)-1) and _my>=_t.y and _my<(_t.y+5) ) then
  _t.over = true
 else
  _t.over = false
 end
end

Could be easily simplified to:

function _mot(_t) 
--if mouse is within the text
-- boundaries then set that 
-- text.over to equal true
 _t.over=(_mx>=_t.x and _mx<(_t.x+(#_t.str*4)-1) and _my>=_t.y and _my<(_t.y+5) )
end

Everything is commented best I could, but feel free to ask questions if any arise.

3


This is awesome! You could use this in a game and it would probable get very popular.



[Please log in to post a comment]