class RotationAnim extends Component {
onInit() {
this.subscribe("STOP_ROTATION");
}
onMessage(msg: Message) {
if (msg.action == "STOP_ROTATION") {
this.finish();
}
}
onUpdate(delta, absolute) {
this.owner.rotation += delta;
}
}
// alternative way by using some tricks
new GenericsComponent("RotationAnim")
.doOnMessage("STOP_ROTATION", (cmp, msg) => cmp.finish())
.doOnUpdate((cmp, delta, absolute) => cmp.owner.rotation += delta);
Downwell
void Object::SendEvent(StringHash eventType, VariantMap& eventData) {
SharedPtr<EventReceiverGroup> group(context->GetEventReceivers(this, eventType));
if (group) {
group->BeginSendEvent();
for (unsigned i = 0; i < group->receivers_.Size(); ++i) {
Object* receiver = group->receivers_[i];
// Holes may exist if receivers removed during send
if (!receiver) continue;
receiver->OnEvent(this, eventType, eventData);
// If self has been destroyed as a result of event handling, exit
if (self.Expired()) {
group->EndSendEvent();
context->EndSendEvent();
return;
}
processed.Insert(receiver);
}
group->EndSendEvent();
}
}
# No arguments.
signal your_signal_name
# With arguments.
signal your_signal_name_with_args(a, b)
func _at_some_func():
instance.connect("your_signal_name", self, "_callback_no_args")
instance.connect("your_signal_name_with_args", self, "_callback_args")
func _at_some_func():
emit_signal("your_signal_name")
emit_signal("your_signal_name_with_args", 55, 128)
some_instance.emit_signal("some_signal")
public interface ICustomMessageTarget : IEventSystemHandler
{
// functions that can be called via the messaging system
void Message1();
void Message2();
}
public class CustomMessageTarget : MonoBehaviour, ICustomMessageTarget
{
public void Message1()
{
// handle message
}
public void Message2()
{
// handle message
}
}
// sending message
ExecuteEvents.Execute<ICustomMessageTarget>(target, null, (x,y) => x.Message1());
// scene initialization
Crafty.e('2D, Canvas, Color, Twoway, Gravity')
.attr({x: 0, y: 0, w: 50, h: 50})
.color('#F00')
.twoway(200)
.gravity('Floor');
// event binding
square.bind("ChangeColor", function(eventData){
this.color(eventData.color);
})
// event trigger
square.trigger("ChangeColor", {color:"blue"});
// custom component
Crafty.c("Square", {
init: function() {
this.addComponent("2D, Canvas, Color");
this.w = 30;
this.h = 30;
},
remove: function() { Crafty.log('Square was removed!'); }
})
Crafty.c("PowerUp",{
init:function() {
this.requires("2D,Canvas,Collision")
.onHit("PlayerBullet",function() { // destroy powerup on hit
this.destroy();
})
.onHit("Player",function(ent) { // apply the effect when player is nearby
ent[0].obj.trigger(this.effect,this.value);
this.destroy();
})
// move the powerUp down
.bind("EnterFrame",function(){
this.y+=2;
});
}
});
Crafty.c("Heal",{
effect:"RestoreHP", value:1,
init:function(){
this.requires("PowerUp,heal");
}
});
WorldConfiguration config = new WorldConfigurationBuilder()
.dependsOn(MyPlugin.class)
.with(
new MySystemA(),
new MySystemB(),
new MySystemC(),
).build();
World world = new World(config);
public class Health extends Component {
public int health;
public int damage;
}
// system for three special towers
public RangeTowerSystem() : base(Aspect.All(typeof(Tower)).GetOne(typeof(Ballista),
typeof(Cannon),typeof(MageTower)))
{
....
}
public class MovementSystem extends EntityProcessingSystem {
public MovementSystem() { super(Aspect.all(Position.class, Velocity.class)); }
}
// new archetype
Archetype dragonArchetype =
new ArchetypeBuilder()
.add(Flaming.class).add(Health.class).build(world);
// extended archetype
Archetype undeadDragon =
new ArchetypeBuilder(dragonArchetype)
.add(FrozenFlame.class).remove(Flaming.class).build(world);
// create new transmuter
this.transmuter = new EntityTransmuterFactory(world)
.add(FrozenFlame.class).remove(Flaming.class).build();
// apply transformation to entity
this.transmuter.transmute(entity);
public class MyPlugin implements ArtemisPlugin {
public void setup(WorldConfigurationBuilder b) {
// hook managers or systems.
b.dependsOn(TagManager.class, GroupManager.class);
// Optionally Specify loading order.
b.with(WorldConfigurationBuilder.Priority.HIGH, new LoadFirstSystem());
// And your custom features
b.register(new MyFieldResolver());
}
}
private static void startBlackHoleGravity(Entity blackHoleE) {
SpasholeApp.ARTEMIS_ENGINE.getSystem(Box2dWorldSystem.class).setEnabled(false);
SpasholeApp.ARTEMIS_ENGINE.getSystem(Box2dBodySystem.class).setEnabled(false);
BlackHoleGravitySystem.setBlackHole(blackHoleE);
// add BlackHoleGravitySystem.components
IntBag actors = Aspects.ACTORS.getEntities();
for (int i = 0; i < actors.size(); i++) {
int actorId = actors.get(i);
if (actorId != blackHoleE.getId()) {
BlackHoleGravitySystem.components.create(actorId);
}
}
}
// RocketComponent
void OnTriggerEnter2D (Collider2D col) {
// If it hits an enemy...
if(col.tag == "Enemy") {
// ... find the Enemy script and call the Hurt function.
col.gameObject.GetComponent<Enemy>().Hurt();
// Call the explosion instantiation.
OnExplode();
// Destroy the rocket.
Destroy (gameObject);
}
// Otherwise if it hits a bomb crate...
else if(col.tag == "BombPickup") {
// ... find the Bomb script and call the Explode function.
col.gameObject.GetComponent<Bomb>().Explode();
// Destroy the bomb crate.
Destroy (col.transform.root.gameObject);
// Destroy the rocket.
Destroy (gameObject);
}
}
IEnumerator Spawn () {
// Create a random wait time before the prop is instantiated.
float waitTime = Random.Range(minTimeBetweenSpawns, maxTimeBetweenSpawns);
// Wait for the designated period.
yield return new WaitForSeconds(waitTime);
// Instantiate the prop at the desired position.
Rigidbody2D propInstance = Instantiate(backgroundProp, spawnPos, Quaternion.identity) as Rigidbody2D;
// Restart the coroutine to spawn another prop.
StartCoroutine(Spawn());
}
IEnumerator BombDetonation() {
// Play the fuse audioclip.
AudioSource.PlayClipAtPoint(fuse, transform.position);
// Wait for 2 seconds.
yield return new WaitForSeconds(fuseTime);
// Explode the bomb.
Explode();
}
bullet.gd:
func _on_bullet_body_enter( body ):
if body.has_method("hit_by_bullet"):
body.call("hit_by_bullet")
enemy.gd:
func _physics_process(delta):
var new_anim = "idle"
if state==STATE_WALKING:
linear_velocity += GRAVITY_VEC * delta
linear_velocity.x = direction * WALK_SPEED
linear_velocity = move_and_slide(linear_velocity, FLOOR_NORMAL)
new_anim = "walk"
else:
new_anim = "explode"
func hit_by_bullet():
state = STATE_KILLED
var world = new World();
world
.registerSystem(MoveSystem)
.registerSystem(RendererSystem);
class MoveSystem extends System {
execute(delta, time) {
this.queries.moving.results.forEach(entity => {
let pos = entity.getMutableComponent(Position);
pos.x += entity.getComponent(Velocity).x;
});
}
}
Nodus for Unity, deprecated
FlowCanvas for Unity
Unreal Blueprints
Pure Data
Blender 3D
It's in the game!