Package framework.spacial.rotational

Source Code of framework.spacial.rotational.SpinComponent

package framework.spacial.rotational;

import java.io.IOException;

import framework.component.util.FloatValueComponent;
import framework.event.Event;
import framework.event.EventListener;
import framework.event.EventSystem;
import framework.io.CustomInputStream;
import framework.spacial.OrientationComponent;
import framework.timing.SystemClockComponent.TimePassedEvent;

public class SpinComponent extends FloatValueComponent implements EventListener{

  public SpinComponent(CustomInputStream in, int baseID, byte versionNum) throws IOException {
    super(in, baseID, versionNum);
  }

  public SpinComponent(float value) {
    super(value);
    EventSystem.getInstance().registerEventListener(this, "TimePassed", null);
  }

  @Override
  public boolean allowSameTypedSiblings() {
    return false;
  }

  @Override
  public void onEvent(Event e) {
    if(e != null){
      if(e.getType().equals("TimePassed")){
        OrientationComponent orientaion = (OrientationComponent) getSiblingByType(OrientationComponent.class.getName());
        if(orientaion != null){
          TimePassedEvent t = (TimePassedEvent) e;
          orientaion.setValue(orientaion.getValue()+t.getDelta()*this.getValue());
        }
      }
    }
  }
}
 
TOP

Related Classes of framework.spacial.rotational.SpinComponent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.