• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unload image when outside of window

 
Ranch Hand
Posts: 36
Mac OS X IntelliJ IDE Java ME
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 30K+ BufferedImages, but I only want to load the ones inside the view to save processing power.

My current code is


this.cord[0] is the image's x position, this.cord[1] is the image's y position, Main.WIDTH is the width of the window and Main.HEIGHT is the height of the window.

gp.player.x is the x position of the player, which can move around in the window and can move the background tiles(what I want to load) around.

this code doesn't seem to work(I found out that it is still loading 100k+ images when there are only ~30K visible).

Can anyone explain my code and tell me how to make it actually work?

 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would slap a bunch of print statements in there to see if the variables actually contain what you think they do.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code snippet doesn't seem to show where the 100K images are being "loaded".
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the code that loads the images?
 
Justan Jefferson
Ranch Hand
Posts: 36
Mac OS X IntelliJ IDE Java ME
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Where is the code that loads the images?



The images loading class is very complicated, so can you tell me why you need it and what part of it do you need?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you say you're having problems with too many images being loaded and yet you don't show us the code that loads the images. Seems like straight forward deduction.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

why you need it


You asked:

I only want to load the ones inside the view


How does the code decide to load an image?
 
Justan Jefferson
Ranch Hand
Posts: 36
Mac OS X IntelliJ IDE Java ME
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:

why you need it


You asked:

I only want to load the ones inside the view


How does the code decide to load an image?



Currently, the code loads all the images, even if they are outside of the window/viewport. I want to only draw the ones inside the window(the ones that the user can see). Does the Graphics2D.draw decide which ones to draw and which ones to don't?
 
Justan Jefferson
Ranch Hand
Posts: 36
Mac OS X IntelliJ IDE Java ME
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:This discussion would fit better in our GUIs forum.



how do I change it?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Justan Jefferson wrote:

Campbell Ritchie wrote:This discussion would fit better in our GUIs forum.



how do I change it?

Already done. Swing/ etc
 
Justan Jefferson
Ranch Hand
Posts: 36
Mac OS X IntelliJ IDE Java ME
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok ty
Content minimized. Click to view
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Justan Jefferson wrote:Currently, the code loads all the images, even if they are outside of the window/viewport. I want to only draw the ones inside the window(the ones that the user can see). Does the Graphics2D.draw decide which ones to draw and which ones to don't?


So your problem is that it attempts to draw 100k images and not just 30k - am I right?
 
Justan Jefferson
Ranch Hand
Posts: 36
Mac OS X IntelliJ IDE Java ME
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

Justan Jefferson wrote:Currently, the code loads all the images, even if they are outside of the window/viewport. I want to only draw the ones inside the window(the ones that the user can see). Does the Graphics2D.draw decide which ones to draw and which ones to don't?


So your problem is that it attempts to draw 100k images and not just 30k - am I right?



Yes. And I want a way to limit it by only drawing the ones that are inside the window.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:I would slap a bunch of print statements in there to see if the variables actually contain what you think they do.

 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

only drawing the ones that are inside the window.


Do they need to be 100% inside
or can only part of them be inside and part of them be outside?


Why is the player's position used in the selection code?
 
Justan Jefferson
Ranch Hand
Posts: 36
Mac OS X IntelliJ IDE Java ME
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

Carey Brown wrote:I would slap a bunch of print statements in there to see if the variables actually contain what you think they do.


I printed and found that the array I was using was for a different purpose. I now used the correct variable, and it worked!

Here is the working if statement:



   
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic