Home | About | Account | Forums | Games
Guest   | Login
  Index  | Recent Threads  | Register  | Search  | Help  | RSS feeds  | View Unanswered Threads  
  Search  


Quick Go »
Thread Status: Normal
Forum Status: Locked
Total posts in this thread: 3
[Add To My Favorites] [Watch this Thread]
Author
Previous Thread This topic has been viewed 11888 times and has 2 replies Next Thread
Skovran
Stranger



Joined: Mar 6, 2005
Posts: 13
Status: Offline

Moving animated Sprites

Hi!

Am I correct in thinking you are not supposed to move animated sprites?

Here's my situation: I have a sprite that moves along a grid under the mouse. This is done by calling sprite.setLocation() from a MouseMotionListener.mouseMoved() handler. When I click the mouse, I would like the sprite to also gleam. I am doing this by adding a GleamAnimation for the sprite from the MouseListener.mousePressed() handler.

What actually happens is that the sprite gleams, but leaves a trail of ghost images while it is moved. The ghost images disappear when I move the sprite over them again.

The Sprite.setLocation() method marks as dirty both the old and new bounds of the sprite, so the regions should be getting redrawn by the RegionManager.

The FrameManager appears to tick the MediaPanel in the AWT thread using EventQueue.invokeLater(), so there should not be any thread problems rendering the sprite.

Any suggestion on what I might be doing wrong, or is this just something that should not be done?
[Sep 17, 2006 1:20:39 PM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
Tirix
Member
Member's Avatar


Joined: Jul 27, 2005
Posts: 57
Status: Offline
Re: Moving animated Sprites

Ouch ! That seems to be a difficult one...

I don't have access to the code right now, so I cannot look at it closely. I have just checked the API (and tcarr's tutorial :) )

* The other animations I know work with Mirages, not Sprites. So they will not modify a given sprite, but simply draw some other image on the media. Maybe you should check that the GleamAnimation is not referring to the Sprite only for getting it drawn ?
* Or maybe the fact that it is working with Sprites implies special restricitions ? (the willStart method seems to be specific to the GleamAnimation)

* You have verified that the "setLocation" and the "tick" methods both are called in the AWT thread. But AFAIK the "paint" method is called in another thread. Maybe you could also dig in that direction ?

Anyway just tracks...

PS. Did I already tell you I like Roshambo a lot ?
[Sep 17, 2006 8:03:51 PM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
Skovran
Stranger



Joined: Mar 6, 2005
Posts: 13
Status: Offline

Re: Moving animated Sprites

I finally figured this out, and it is pretty ugly. The GleamAnimation temporarily removes the sprite from the SpriteManager. An unmanaged sprite cannot notify the RegionManager when it is moved. Therefore, the old location of the sprite is never marked as dirty. Wee.

Here is my ... well let's generously call it a "fix":

if (!_media_panel.getSpriteManager().isManaged(sprite)) {
Rectangle dirty=new Rectangle(sprite.getBounds());
_media_panel.getRegionManager().addDirtyRegion(dirty);
}
sprite.setLocation(...);

This does some of the work that setLocation() would have done if the sprite were still managed.

 
PS. Did I already tell you I like Roshambo a lot ?

No, and thanks! It was a good tool for learning the game libraries.
[Sep 18, 2006 2:50:50 AM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
[Show Printable Version of Thread]

Home | About | Account | Forums | Games           ©2005 Three Rings Design, Inc