Comments (5)
Have you read through the SPECS book?
from specs.
Yeah I've read through it :( Basically, what I need is a way to just do like "Entities.get_entity_with_tag("paddle")" or something like that. Because, I need to access the Transform component on the paddle Entity from the ball System to check for collisions.
from specs.
I figured out a temporary solution. Is this good?
struct BallSystem;
impl<'a> System<'a> for BallSystem {
type SystemData = (
ReadStorage<'a, Transform>,
WriteStorage<'a, RigidBody>,
ReadStorage<'a, Ball>,
ReadStorage<'a, Paddle>,
);
fn run(&mut self, (transform, mut rigidbody, ball, paddle): Self::SystemData) {
for (e_transform, e_rigidbody, e_ball) in (&transform, &mut rigidbody, &ball).join() {
if is_key_pressed(KeyCode::Space)
&& e_rigidbody.velocity == Vec2::ZERO {
e_rigidbody.velocity = vec2(e_ball.move_speed, -e_ball.move_speed);
}
if e_transform.position.x < 0.0
|| e_transform.position.x > SCREEN_WIDTH as f32 - 13.0 {
e_rigidbody.velocity.x *= -1.0;
}
if e_transform.position.y < 0.0 {
e_rigidbody.velocity.y *= -1.0;
}
for (p_transform, _p_paddle) in (&transform, &paddle).join() {
if e_transform.position.y + 13.0 > p_transform.position.y
&& e_transform.position.x + 13.0 > p_transform.position.x
&& e_transform.position.x < p_transform.position.x + 80.0
&& e_rigidbody.velocity.y > 0.0 {
e_rigidbody.velocity.y *= -1.0;
}
}
}
}
}
from specs.
I figured out a temporary solution. Is this good?
Yes. SPECS does not support querying for specific entities with certain components, only the set of all entities with a particular set of components.
If specific entities have a special meaning in your project then I'd advise storing their Entity
in some global resource to make finding them faster.
from specs.
Ok! Thank you for your help! I'm not very experienced with Rust if you couldn't tell XD
from specs.
Related Issues (20)
- How do I get the Entity that a Component belongs to? HOT 1
- How to get an entt like view of entities within a system? HOT 2
- How do I create a system that also has the capacity to remove entities? HOT 1
- Migrate to Rust 2021
- [Question] Is it possible to group components together (to all be accessed by 1 system) HOT 3
- `EntityResBuilder` does not implement `Builder` HOT 1
- Specs vs legion HOT 2
- Best practice for borrowed resources in systems? HOT 4
- ecs_bench_suite fragmented_iter unexpectedly slow
- Add necessity of feature flag serde to api documentation for saveload HOT 2
- LazyUpdate::exec uses a &mut ref? HOT 1
- specs uses shred 0.13.0, which depends on mopa HOT 1
- Re-add support for dynamic components (for scripting) HOT 1
- 0.19.0 Release? HOT 1
- ahash 7.5 dep yanked HOT 2
- Compilation fails due to outdated depencendy on ahash 0.7.7 HOT 1
- specs-derive better 'storage' macro parameter
- The specs book domain is abandoned HOT 3
- Add a section in readme linking to other options 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 specs.