Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

SSK2: with camera, how to know is an object is visible?
Started by pascal.lemerrer Feb 26 2018 12:46 AM

2 replies to this topic
ssk2 camera

Best Answer roaminggamer , 26 February 2018 - 04:52 PM

Sure, it would be something like this:

local function isInView( obj, player )
   local xMin = player.x - fullw/2
   local xMax = player.x + fullw/2
   local yMin = player.y - fullh/2
   local yMax = player.y + fullh/2

   if( obj.x > xMax ) then return false end
   if( obj.x < xMin ) then return false end
   if( obj.y > yMax ) then return false end
   if( obj.y < yMin ) then return false end

   return true
end

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

pascal.lemerrer

[GLOBAL: userInfoPane.html]
pascal.lemerrer
  • Observer

  • 5 posts
  • Corona SDK

Hi

 

I use SSK2 camera with the tracking mode.

I there any way to know if an object is outside the visible part of the world?



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,487 posts
  • Corona SDK

  Best Answer

Sure, it would be something like this:

local function isInView( obj, player )
   local xMin = player.x - fullw/2
   local xMax = player.x + fullw/2
   local yMin = player.y - fullh/2
   local yMax = player.y + fullh/2

   if( obj.x > xMax ) then return false end
   if( obj.x < xMin ) then return false end
   if( obj.y > yMax ) then return false end
   if( obj.y < yMin ) then return false end

   return true
end



[TOPIC: post.html]
#3

pascal.lemerrer

[GLOBAL: userInfoPane.html]
pascal.lemerrer
  • Observer

  • 5 posts
  • Corona SDK

Thank you!




[topic_controls]
[/topic_controls]