Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  Removing GameObjects(Units)  (Read 1158 times)
0 Members and 1 Guest are viewing this topic.
Offline stef569

Junior Member





« Posted 2008-08-30 17:53:13 »

Hi,

I'm having troubles to remove an entity and it's bound sprite object when it should die.
a unit is an entity
an entity has 3 states:
IDLE, DESTROYED,

My design:
gameState has ref to model and gui
when model changes event is sent to gui
gui can read from the model

So:
2 units batter
1 units hp is 0
that unit changes to the DESTROYED state

the gui sprite reads the state and changes to the explosion animation:
inside the sprite:
if ent.getState() == destroyed
 setAnim(explosion)
 
I know how long the explosion anim would take
...
the explosion anim is done.

Now how should I remove the entity in the model...
I know howto remove an entity: map.getTile(0,0).setEntity(null) and that's it.
But

I can only remove it when the explosion time has elapsed.
else the sprite won't paint itselfs(ie the explosion) anymore
I can not remove it from within the gui(see my design)

my painting code:
for(Entity ent : map.getAllEntities()) {
   if(spriteCache.contains(ent) {
    spriteCache.get(ent).paintComponent(g);
   } else {
   // Create new sprite for this ent.
   }
}

So if i remove the entity in the model it will not be painted anymore :/

I can think of one way remove the explosionAnim from the unitSprite and add it to the main gui
then if ent.state == destroyed play the anim and when done remove the sprite bound to the ent.

What other solutions are there. or what is the general way to handle this problem.
Offline Wildern

Junior Member





« Reply #1 - Posted 2008-08-30 18:09:06 »

Maybe add a state for dying, which is when the explosion or other death animation plays.  And when that animation finishes, it sets the state to destroyed.  Any object in the destroyed state could then be safely removed.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2008-08-30 18:11:12 »

You can also just change your program structure a bit so that you can simply inform the model when it's the right time to remove the object.

See my work:
OTC Software
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (40 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!