Make a hitbox inside a newImage

I’ve seen the question asked before, but that was in relation to SpriteLog.

  1. So, is it possible to create a smaller “hitbox” inside a simple small transitioning image?
  2. Is it possible to make two(this might be answered in question 1)? [import]uid: 21652 topic_id: 14703 reply_id: 314703[/import]

I usually use this hitTest method to make the hit zone bigger or smaller than the display objects:

function hitTestObjects(obj1, obj2, dist)  
 local dist = dist or 30 -- 30 is default if dist = nil  
 local sqrt = math.sqrt  
 local dx = obj1.x - obj2.x  
 local dy = obj1.y - obj2.y  
 local distance = sqrt(dx\*dx + dy\*dy)  
 -- distance = actual distance  
 -- dist = hit zone radius  
  
 if distance \< dist then   
 return true  
 else  
 return false  
 end  
end  

usage:

if hitTestObjects(obj1, obj2, 20) then  
 print ("HIT!")  
end  

hope that helps!
-finefin [import]uid: 70635 topic_id: 14703 reply_id: 54376[/import]

Thanks, that worked great. I actually had some similar code already in my game… just proves that interacting, even through a forum helps your brain think. Just being alone is not a formula for success. :slight_smile: [import]uid: 21652 topic_id: 14703 reply_id: 54402[/import]