AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Tutorial 2.7: EntitySystem

Ein Thema von DP News-Robot · begonnen am 13. Apr 2020
Antwort Antwort
Benutzerbild von DP News-Robot
DP News-Robot

Registriert seit: 4. Jun 2010
14.979 Beiträge
 
#1

Tutorial 2.7: EntitySystem

  Alt 13. Apr 2020, 23:01
Can we finally go out and play now? Hold on Smurfs. As usual with programming, with every new thing you create, 2 other problems arise that require something else to be made first. In this case, we still need to do a few things:
· Somebody has to call “Entity.update()” (for all active entities) – to animate
· Create some animations to test with (in “Resources.java”)
· Adjust the Game code so it will actually use an entity instead
· Something to think about, who will set the animations? The Puppetmaster?

Problem 4 is a future problem. Problem 2 and 3 are peanuts. Problem 1 requires a bit more attention. We could cheat, skip it, and just call update on that particular entity in our Game render cycle, instead of making another “Entity Manager” class. That will work... until you have 100 entities, created on the fly. Sigh, ok then, another file: “EnEntitySystem.java”.
public class EnEntitySystem {

int uniqueId;

ArrayList entities;

public EnEntitySystem()
{
uniqueId = 1;
this.entities = new ArrayList();
} // create


public void update( float deltaSecs )
{
// Update all entities, and remove those who got killed
int i=0;
while ( i < this.entities.size() ) {
EnEntityBase ent = this.entities.get( i );
if ( !ent.update( deltaSecs ) ) {
this.entities.remove( i );
ent.dispose();
} else
++i;
}

} // update


public EnEntityBase get( int id )
{ // Brute force search
for (int i=0; i
So we have an array of entities. The EntitySystem allows to create sprites or to add your own custom entities. Both are added to the array, so they will be updated once the engine does its “update” routine. Furthermore, you can search for entities by id or name. And that’s pretty much it. For now.


Earlier on, we started a simple "Engine.java" file, where we create the main sub-systems, do the rendering, and call the updates. Of course, our EntitySystem belongs there as well:
public class Engine {
float deltaSecs;

GxCamera camera;
GxImageLibrary imageLibrary;
EnEntitySystem entitySystem;

public Engine()
{
this.camera = new GxCamera();
this.imageLibrary = new GxImageLibrary();
this.entitySystem = new EnEntitySystem();
} // create

...

public void update()
{
this.deltaSecs = Gdx.graphics.getDeltaTime();

this.camera.update( this.deltaSecs );
this.entitySystem.update( this.deltaSecs );
//this.controls.update( this.deltaSecs );
//this.physics.update( this.deltaSecs );
//this.world.update( this.deltaSecs );
//this.soundManager.update( this.deltaSecs );
} // update

...

public EnEntitySystem getEntitySystem()
{
return this.entitySystem;
}

} // Engine
Now FINALLY, we can start making real use of that so called “Engine”!



Weiterlesen...
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:42 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz