(Resolved) In Screen

Started by nathmatt, October 04, 2011, 08:24:04 am

Previous topic - Next topic

nathmatt

October 04, 2011, 08:24:04 am Last Edit: October 04, 2011, 10:51:01 am by nathmatt
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

Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Blizzard

October 04, 2011, 09:49:25 am #1 Last Edit: October 04, 2011, 09:58:28 am by Blizzard
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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

nathmatt

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
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Blizzard

I probably messed up something trivial. In any case, you got it working. That's what counts.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.