Comments (2)
仔细想想也不需要由ecs插件来提供这种功能。完全由用户自己来做这不麻烦。
用户自己定义一个“能力”组件添加到实体身上,或者写个系统来动态给实体添加“能力”组件。
from ecs.
@ecs.register('Node ')
class NodeComponent extends ecs.IComponent {
val: Node;
reset() {
this.val= null;
}
}
@ecs.register('Movement')
class MovementComponent extends ecs.IComponent {
speed: number = 1;
heading: Vec2 = v2(0, 0);
pos: Vec2 = v2(0, 0);
move(dt: number) {
this.pos.x += this.speed * this.heading.x;
this.pos.y += this.speed * this.heading.y;
}
reset() {
}
}
@ecs.register('Render')
class RenderComponent extends ecs.IComponent {
show(dt: number) {
let node = this.ent.Node.val;
let moveComp = this.ent.Move;
moveComp.move(dt);
node.setPosition(moveComp.pos);
}
reset() {
}
}
class AddRenderComponentSys extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
filter(): ecs.Matcher {
return ecs.allOf(NodeComponent, MovementComponent).excludeOf(RenderComponent);
}
entityEnter(entities: ecs.Entity[]) {
entities.forEach(e => e.add(RenderComponent));
}
}
class RemoveRenderComponentSys extends ecs.ComblockSystem implements ecs.IEntityRemoveSystem {
filter(): ecs.Matcher {
return ecs.allOf(NodeComponent, MovementComponent, RenderComponent);
}
entityRemove(entities: ecs.Entity[]) {
entities.forEach(e => e.remove(RenderComponent));
}
}
from ecs.
Related Issues (10)
- 提供一种方便添加tag类型组件的方式。
- createComp方法没有导出 HOT 5
- 尝试利用TypeArray优化性能
- IEntityRemoveSystem没有正确监听到entity删除,反而在entity.remove(组件)的时候会被调用 HOT 6
- tag HOT 1
- 测试模块
- 序列化 HOT 2
- Matcher类没有导出? HOT 3
- 强烈建议用这个库去开发Screeps游戏,用代码玩游戏的那个,Steam平台有 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ecs.