Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
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  
  Sprite Movement  (Read 1699 times)
0 Members and 1 Guest are viewing this topic.
Offline pecgv

Junior Newbie

Java games rock!

« Posted 2005-03-03 15:57:14 »

After I moves my Sprite from one place to another,
the original Sprite did not deleted and exists in the Canvas.
So, my question is Should I need to apply LayerManger.remove(Sprite) method to delete the original Sprite everytime?
If I apply paint's drawImage, I only can apply repaint() to eliminate the orginal picture.
Can I apply repaint() instead of LayerManger.remove(Sprite) ?
Thank you~
Offline ameano

Senior Newbie

abstract void

« Reply #1 - Posted 2005-03-04 07:39:57 »


Your sprite will be an instance of the Sprite object that you have created. Using LayerManager.remove will only remove the *reference* to the sprite object you have created, from the LayerManager. To actually free the sprite you will have to set it to null.
Sprite mySprite = new Sprite(parameters...);
do some code...
remove it from layer manager...
mySprite = null;

This will enable the garbage collector to free up the memory used by the sprite. Or you can do a manual system.gc(), which wont necessarily guarantee a garbage collect... but thats beside the point.

You will have to repaint the screen every time a change is made in order to make that change visible to the user...

What I mean is...

Of course you may render your screen every few milliseconds or game ticks. This really is dependant on your code. But what I mean by the above statement is you need to make your code display those changes on the screen. In this case the change is removing the sprite. Using layermanager.remove will remove the sprite from the layer manager. But you will either have to force the layer manager to repaint or have your rendering system do it for you.

Hope this helps.


rules are there to be broken... same goes for the rules of programming classes in j2me
Offline pecgv

Junior Newbie

Java games rock!

« Reply #2 - Posted 2005-03-04 08:14:43 »

I see, thanks a lot.  Smiley
Another question I want to ask is what is the difference between repaint() and flushGraphics() ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ameano

Senior Newbie

abstract void

« Reply #3 - Posted 2005-03-04 13:15:52 »

Not quite sure... but I believe flushGraphics is used when you want to flush the current graphics buffer to the device (screen) and repaint is used when you want to force the graphics context to paint everything again to the current graphics buffer (in double buffered systems), but may not necessarily paint to the screen. Sounds about right.


rules are there to be broken... same goes for the rules of programming classes in j2me
Offline pecgv

Junior Newbie

Java games rock!

« Reply #4 - Posted 2005-03-04 14:19:34 »

I see, thanks a lot Smiley
Offline danielmfreitas

Senior Newbie

Java games rock!

« Reply #5 - Posted 2005-03-07 18:03:45 »

Actually, the diferences between repaint() and flushGraphics() are that repaint informs the application that the Canvas needs to be repainted. The painting operation happens using the Canvas paint() method. Since it is a request, you have no idea when the application will answer your request. But it shall do so sooner or later.

flushGraphics can only be used with gameCanvas(), and its responsibility is to flush the offscreen buffer into the device display. So, the preferred aproach for using GameCanvas is not to override the paint method and ask for a repaint(), but to get the graphics object from the GameCanvas (by calling getGraphics()) drawing stuff with it and then flush the graphics.

The painting operations used with the graphics object returned by the getGraphics() method of GameCanvas will draw on an offscreen buffer, and flushGraphics() will flush the buffer content into the display.

Diferently from the asynchronous behaviour of paint()/repaint(), flushGraphics will only return when the buffer content is fully drawn into the display.

The API docs have some more information about that.
Offline pecgv

Junior Newbie

Java games rock!

« Reply #6 - Posted 2005-03-08 03:12:10 »

Thanks for danielmfreitas !~~ Cheesy
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Riven (24 views)
2015-07-27 16:38:00

Riven (14 views)
2015-07-27 15:35:20

Riven (19 views)
2015-07-27 12:26:13

Riven (9 views)
2015-07-27 12:23:39

BurntPizza (24 views)
2015-07-25 00:14:37

BurntPizza (36 views)
2015-07-24 22:06:39

BurntPizza (20 views)
2015-07-24 06:06:53

NoxInc (23 views)
2015-07-22 22:16:53

NoxInc (15 views)
2015-07-22 22:13:39

Jesse (36 views)
2015-07-22 03:10:36
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!