Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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 1566 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 »

Hi

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.
e.g.
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.

Ameano

Ameano
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() ?
Thanks
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.

Amin

Ameano
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.

 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!