Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Canvas and Images Resizing Proportionately?  (Read 1069 times)
0 Members and 1 Guest are viewing this topic.
Offline _Scyth_

Junior Member





« Posted 2012-12-29 12:13:15 »

   Ok, my next problem is this.

   If a user click on the maximise button at the top of the window, or drags the frame to make it bigger, how can I have it so that my images will resize proportionately with the change in width or height the user has made.

   Or should I just leave it a fixed window with the maximise button disabled.

   I don't even know where to start on this problem so any advice would be great.
Offline Porlus

Junior Member





« Reply #1 - Posted 2012-12-29 13:11:24 »

So you want to be able to resize the window while maintaining the aspect ratio of the canvas?
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #2 - Posted 2012-12-29 13:13:36 »

So you want to be able to resize the window while maintaining the aspect ratio of the canvas?
I guess he first wants to know how to zoom out of his 2D game world. He wants to resize the images and change the position of the sprites to make that happen.

I guess you should take a look at your
glOrtho(...)
. (Are you using OpenGL? :X )
I'm pretty sure it's possible with glOrtho.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline _Scyth_

Junior Member





« Reply #3 - Posted 2012-12-29 13:20:22 »

I'm using Java2D, which probably makes it a little bit more awkward.

And I'd like to be able to do both, to be able to zoom out my 2D world for such things like a map, or minimap and to be able to keep aspect ratio if the user wants to resize the window.

Like I said, I don't even know where to start.
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #4 - Posted 2012-12-29 13:25:35 »

Take a look at AffineTransforms.

They are resposible for translating, scaling, and rotating BufferedImages.
You could also just use the
g.drawImage(buffImg, x, y, width, height);
methods, which take width and height parameters. They automatically "stretch" the image, so they have the desired width and height.

Or you could just switch to OpenGL Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Porlus

Junior Member





« Reply #5 - Posted 2012-12-29 13:28:09 »

Yeah, as matheus says, you can use Graphics.drawImage to scale your canvas. Smiley Here's an article that explains how you would maintain the aspect ratio and also calculate the margins.

http://blog.acamara.es/2012/02/05/keep-screen-aspect-ratio-with-different-resolutions-using-libgdx/
Offline greenOwl

Junior Member


Medals: 1


from Germany


« Reply #6 - Posted 2012-12-29 13:28:39 »

You have to think about what you want to do with the new available space you get from expanding your window.
> you could show more of the map or whatever you rendering (no scaling neccssary)
> you could scale your your images up to fill the space (you will have to scale BuffereImages e.g. using AffineTransforms)
This could get complicated especially if your images have the resolutions matching your smaller (regular) screen. In this case you have to use interpolation (AffineTransforms have that option if I remember correctly)
> ...

You have to be more specific what you actually want to do with that space

greenOwl

elfeck
Offline _Scyth_

Junior Member





« Reply #7 - Posted 2012-12-29 13:40:49 »

Ok, I'm not really using a graphic engine as such, so I'm guessing showing more of the map would be better.

I've decided that, I could have two variables like
1  
int tilewidth, tileheight;

And then when I render my tiles I can do:
1  
g.drawImage(img, x*tilewidth, y*tileheight, tilewidth, tileheight);


Then if the user scrolls the mouse wheel, then I can have tilewidth and tileheight to change or I could simply have a little icon for zooming in or out. I would need to restrict how far to zoom in, otherwise I could end up with a single tile taking up 640x400 or whatever resolution I finally end up with.

If the user resizes the window, will it automatically render more of my map?
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #8 - Posted 2012-12-29 13:44:24 »

Use Java2D full screen or fake full screen and scale your image a fixed amount. This way you control the size of the screen yourself.

Offline _Scyth_

Junior Member





« Reply #9 - Posted 2012-12-29 13:58:26 »

Yes, I suppose using Fullscreen would eliminate the fear of the user resizing the window.

Thanks for the advice and suggestions everyone!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!