Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: nathmatt on October 04, 2011, 08:24:04 am

Title: (Resolved) In Screen
Post by: nathmatt on October 04, 2011, 08:24:04 am
im trying to get an array of events in the maps screen for update purposes but for some reason its not working properly here the script by the way its VX so Graphics.width & Graphics.height are the screen sizes

def in_screen?
 x,y = (@display_x/32),(@display_y/32)
 w,h = x+(Graphics.width/32),y+(Graphics.height/32)
 return @events.values.collect{|value| value if (x..w).include?(value.x) &&  
 (y..h).include?(value.y)}
end

Title: Re: In Screen
Post by: Blizzard on October 04, 2011, 09:49:25 am
Try this. The mistake you made is fixed, and it works properly if you're and/or events are moving.

def in_screen? # a display/real value is actually pixels * 4
 x = @display_x + Graphics.width * 4 - 1
  y = @display_y + Graphics.height * 4 - 1
 return @events.values.find_all {|event| event.real_x.between?(@display_x, x) && event.real_y.between?(@display_y, y)}
end


Keep in mind that this doesn't take into account graphic size of the event so events with graphics bigger than 32x32 pixels won't be in the result even if the graphic is visible on the screen, but the event is outside of the screen.
Title: Re: In Screen
Post by: nathmatt on October 04, 2011, 10:41:23 am
that wasn't working right either this works good tho

def in_screen? 
  return @events.values.find_all {|event| event.screen_x.between?(0, Graphics.width) &&
  event.screen_y.between?(0, Graphics.height)}
end
Title: Re: In Screen
Post by: Blizzard on October 04, 2011, 10:49:50 am
I probably messed up something trivial. In any case, you got it working. That's what counts.