Results 1 to 3 of 3
- 05-23-2011, 04:08 PM #1
Member
- Join Date
- Nov 2010
- Location
- VT, USA
- Posts
- 31
- Rep Power
- 0
Adding animation for a series of moves
Hi,
I am keeping a deck of cards, as imageIcons in JLabels, as laid out on a JLayeredPane. I have just discovered that moving a card in the event dispatch thread slowly across the screen doesn't have any repainting in it (even with repaint() and vaildate() and all of this).
I have my existing code. There are various legal play types, and each makes calls to move cards when it is time to make a play. Currently, a move simply changes the location of a card. A single play, however, could involve up to two moves and two flips. I will also want a little animation in the flips. So I am in my playType code, say, and I want to issue a few commands, in series, to cause animation of one thing at a time, then the next, and then done.
I can't have the user being able to click on anything until the animation is done. I could skip mouse listeners on cards while animation is flagged.
The thing is, the playType "makePlay()" function is where the controller is. I have a dozen PlayType subclasses, each of which knows a series of moves and flips of its own. Such a controller function needs to be able to issue a series of animation requests (and then be done).
How should I approach this? Should I make a "List" of moves, and then have those moves being executed by events I fire to myself? Can I make a component of some kind that I just use to fire events to myself? My PlayType classes have no sense of the GUI, and do not have gui controls. They reference the "board[][]", which has rows and columns of CardStack objects. Then their makePlay() and makeReversePlay() functions make calls to move and flip cards.
TIA, and cheers -
Mark
- 05-23-2011, 05:22 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
Sounds good.Should I make a "List" of moves,
See How to Use Swing Timers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features). Each time the Timer fires you invoke the next move.and then have those moves being executed by events I fire to myself?
- 05-23-2011, 05:50 PM #3
Member
- Join Date
- Nov 2010
- Location
- VT, USA
- Posts
- 31
- Rep Power
- 0
Thank you for the link. That is funny. I must have thought a timer was not something to look at, because I tried adding a call to Thread.sleep(), and that didn't work. It really did spend a second moving the location of card across the screen - it just didn't paint.
Hey, I can get an event from a timer. It runs in a timer thread. I can practically use the same code (but not in a loop) to move one card.
Thanks again -
Mark
Similar Threads
-
Alternating between players moves in a game
By nephos in forum New To JavaReplies: 3Last Post: 04-18-2011, 08:39 AM -
shrinking components when a JSplitPane moves or slided
By bigj in forum New To JavaReplies: 6Last Post: 01-31-2010, 01:44 PM -
Bishops moves
By michail in forum New To JavaReplies: 5Last Post: 01-28-2010, 09:33 PM -
Adding popup Menu on animation
By Peggy in forum Java AppletsReplies: 2Last Post: 12-10-2008, 08:33 AM -
how u rotate the arrow mark as the line moves accordingly
By sandhyau in forum AWT / SwingReplies: 1Last Post: 02-16-2008, 11:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks