Hamy
unread,Jan 24, 2009, 10:23:55 PM1/24/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Javassonne Discussion
So the main stuff for the scrolling window's is working, and we can
meet our user story. Massive email continues...
So if you update, and run swing demo's you will now see four green
squares. Click on those beast's to scroll around. There are still some
minor bugs, like the screen sometimes doesn't refresh in time, and
there is definitely room for improvement, and the basic plan is as
follows:
make it so you only have to hover on the buttons to initiate scrolling
add buttons to the top/left/right/bottom so you can go in those
directions
make all buttons transparent, so you simply hover on the edge of the
screen and scroll around
adam suggested we put a few buttons, rather than one, so that the
closer you get to the edge of the screen the faster you scroll. I
think this sounds pretty sweet.
So that's about it. If you are interested in how it works, there is a
decent description below, and there are nice code comments.
hamy
How this snazz is working:
so basically you have gamewindow, which is a JLayeredPane. The JLP
contains lightweight components that stack on top of one another so
you can create a layered appearance with things.
The hard part of all of this is that the JLP itself, and all panes it
contains, must be the same size. Remember that
So basically there is one pane, called the default pane, which is
meant to be your background pane. (kind of like setting a background
image). Inside of the default pane I have the map (by which I mean the
images and the grid). If I simply added the whole map to the pane, it
would either a)scale itself to fit in the window or b)go off the
edges, and we would not be able to scroll around. It would be
immobile :(
so the default pane(the MapLayer, for us...its a private class inside
WorldCanvas) contains something called a JViewport, which allows us to
get a sort of "window" on the map, and scroll around. The JViewport
needs to be able to add something to itself to be behind the window,
so there is a class called map inside of the MapLayer which is placed
behind the JViewport. Now we have a scrollable map. Yay!
Remembering that each pane needs to be the same size, we stutter
around setting the size of the JLP and all its panes(currently just
the default and palette layer) to the size that the Map class decided
it would make the rendering of the map.
The other panes can now be used to create layered content anywhere on
top of the game map. For now, we just have the palette pane with its
nav buttons, but there are infinite more possible. Because all the
other panes are technically super huge, we need to render relative to
the size of the screen, not to the size of the panes. So we pass in a
Dimension called screenSize, and use that to help us figure out where
we should be rendering stuff like the nav buttons.
Then you wire up the event listeners, and add a small interface to
world canvas to request operations be performed on the map(like
scrolling), and whala! Scroll featuring.
Good benefits of this include the ability to render panes
independently, and the ability to isolate the code required for
drawing certain things. (aka we dont have to put the code for drawing
meeples and the code for drawing the tiles all in one place and figure
it out) Yay extensibility.
See yall tomorrow