jadpole / jadpole.github.io Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://jadpole.github.io
Home Page: https://jadpole.github.io
events.rs:1:5: 1:29 error: unresolved import sdl2::event::EventPump
. There is no EventPump
in sdl2::event
[E0432]
events.rs:1 use ::sdl2::event::EventPump;
^~~~~~~~~~~~~~~~~~~~~~~~
events.rs:1:5: 1:29 help: run rustc --explain E0432
to see a detailed explanation
error: aborting due to previous error
Could not compile arcade-rs
.
Hi jadpole:
I'm a Rust developer in China,and I want to translte your rust series articles into Chinese, they are brief and easy to learn.
So, Shall I do it ?
At the end of the section you have some utility methods that should be implemented but the types in the function signatures are wrong and your code doesn't have them either. What is the purpose them?
Here: https://github.com/jadpole/jadpole.github.io/blame/master/_posts/2015-12-08-arcaders-1-10.md#L264 you change the context from define AnimatedSprite to define de Asteroids structure, I suppose the file to define it is views/game.rs but I'm not sure, and can be better to explicit specify the file.
Hey,
In chapter 2. Event Handling, the last example code is broken. Now there is:
// Initialize SDL2
let mut sdl_context = sdl2::init().video()
.build().unwrap();
// Create the window
let window = sdl_context.window("ArcadeRS Shooter", 800, 600)
.position_centered().opengl()
.build().unwrap();
But it should be:
// Initialize SDL2
let sdl_context = sdl2::init().unwrap();
let video = sdl_context.video().unwrap();
// Create the window
let window = video.window("ArcadeRS Shooter", 800, 600)
.position_centered().opengl()
.build().unwrap();
Otherwise the code won't compile.
Hello there,
I've been following your tutorial and it's been great so far. There was a version mismatch in one of the earlier lessons so I've been following along while trying to update everything that's changed from the SDL versions at the same time. I've finally ran into a problem I can't seem to solve.
This code:
::sdl2_ttf::Font::from_file(Path::new(font_path), size).ok()
.and_then(|font| {
self.cached_fonts.insert((font_path, size), font);
self.ttf_str_sprite(text, font_path, size, color)
})
within ttf_str_sprite() of Phi no longer works. Specifically, the from_file() function no longer exists in sdl2_ttf::Font (as of sdl2_ttf version 0.14 I believe). From what I've gathered, the only way to load fonts from here on out is directly from the sdl2_ttf context:
impl Sdl2TtfContext {
/// Loads a font from the given file with the given size in points.
pub fn load_font<'a>(&'a self, path: &'a Path, point_size: u16) -> Result<Font, String> {
internal_load_font(path, point_size)
}
// ...
}
That's from the implementation for sdl2_ttf v0.25. I've tried to hobble together a solution that passes along the context created in spawn() by attaching it to the Phi struct:
pub struct Phi<'window> {
pub events: Events,
pub renderer: Renderer<'window>,
pub ttf_context: ::sdl2_ttf::Sdl2TtfContext,
cached_fonts: HashMap<(&'static str, i32), ::sdl2_ttf::Font<'window>>
}
Then doing this in the ttf_str_sprite() function:
pub fn ttf_str_sprite(&mut self, text: &str, font_path: &'static str, size: i32, color: Color) -> Option<Sprite> {
if let Some(font) = self.cached_fonts.get(&(font_path, size)) {
return font.render(text).blended(color).ok()
.and_then(|surface| self.renderer.create_texture_from_surface(&surface).ok())
.map(Sprite::new)
}
//::sdl2_ttf::Font::from_file(Path::new(font_path), size).ok()
self.ttf_context.load_font(Path::new(font_path), size as u16).ok()
.and_then(|font| {
self.cached_fonts.insert((font_path, size), font);
self.ttf_str_sprite(text, font_path, size, color)
})
}
Which gives me all sorts of problems with lifetime conflicts on the load_font() function. I suspect I'm going about this all wrong. Do you have any idea on how to update this method so it works with sdl2_ttf v0.25?
Sorry for the long winded post!
While I noticed the call to timer()
when building the sdl_context
, I can't figure out how to actually use the frame timing code. I guessed that it was added to src/main.rs, but that isn't completely obvious, either.
What do I declare to make the third code example work?
Note: This is fixed in 1.9
Checking out and compiling as-is gives:
phi/mod.rs:33:10: 33:18 error: mismatched types:
expected `u32`,
found `f64`
(expected u32,
found f64) [E0308]
src\phi/mod.rs:33 (w as f64, h as f64)
^~~~~~~~
src\phi/mod.rs:33:10: 33:18 help: run `rustc --explain E0308` to see a detailed explanation
src\phi/mod.rs:33:20: 33:28 error: mismatched types:
expected `u32`,
found `f64`
(expected u32,
found f64) [E0308]
src\phi/mod.rs:33 (w as f64, h as f64)
^~~~~~~~
src\phi/mod.rs:33:20: 33:28 help: run `rustc --explain E0308` to see a detailed explanation
src\views/mod.rs:74:16: 74:42 error: the trait `core::ops::Mul<_>` is not implemented for the type `u32` [E0277]
src\views/mod.rs:74 w: phi.output_size().0 * 0.70,
^~~~~~~~~~~~~~~~~~~~~~~~~~
src\views/mod.rs:74:16: 74:42 help: run `rustc --explain E0277` to see a detailed explanation
src\views/mod.rs:74:16: 74:42 error: the trait `core::ops::Mul<_>` is not implemented for the type `u32` [E0277]
src\views/mod.rs:74 w: phi.output_size().0 * 0.70,
^~~~~~~~~~~~~~~~~~~~~~~~~~
src\views/mod.rs:74:16: 74:42 help: run `rustc --explain E0277` to see a detailed explanation
src\views/mod.rs:75:16: 75:35 error: mismatched types:
expected `f64`,
found `u32`
(expected f64,
found u32) [E0308]
src\views/mod.rs:75 h: phi.output_size().1,
^~~~~~~~~~~~~~~~~~~
src\views/mod.rs:75:16: 75:35 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to 5 previous errors
Could not compile `arcade-rs`.
As the title says the code from chapter 1 just fails on Windows 7, Rust 1.14 nightly (098d22845 2016-10.13) with:
"error: process didn't exit successfully: 'target\debug\arcade-rs.exe' (exit code: 3221225781)".
I tried this code with both the sdl2 version specified in the article (0.13) and the newest one (0.24).
I also tried these both possibilities with the gl-rs bindings downloaded as the code had some mention of using opengl in the creation of window
variable binding.
Am I missing something, like having to download something other than the SDL2 libraries from libsdl.org which I downloaded and put in the right directory already?
Currently, the code in the lesson looks like this:
// ~/src/phi/data.rs
// ...
pub fn to_sdl(self) -> Option<SdlRect> {
assert!(self.w >= 0.0 && self.h >= 0.0);
SdlRect::new(
self.x as i32, self.y as i32, self.w as u32, self.h as u32
)
}
With newer version of sdl2(v0.24.0 specifically) this will fail at the compile step as Renderer.copy()
expects 2 Option<Rect>
's as arguments. I'm fairly new to Rust, but I fixed the issue by changing the code to the following:
pub fn to_sdl(self) -> Option<SdlRect> {
assert!(self.w >= 0.0 && self.h >= 0.0);
Some(SdlRect::new(
self.x as i32, self.y as i32, self.w as u32, self.h as u32
))
}
Let me know if you think this a good solution.
I enjoyed the series a lot! A few things I noticed while reading parts 1-11:
use
paths are always relative to the crate root. You can omit all leading ::
in them, which gets rid of some visual clutter.// note: does not compile anymore
?thread::sleep_ms
is deprecatedImmediateEvents
could get a Default
derive, which gets rid of the impl ImmediateEvents
x == true
which is unneeded.region()
(when explaining struct update syntax), the "rect would be made invalid" wouldn't matter since it's consumed by the function anyway.mem::replace
and direct reassignment make the bullet update code much shorter: let old_bullets = mem::replace(&mut self.bullets, vec![]);
self.bullets = old_bullets.into_iter().filter_map(|b| b.update(phi, elapsed)).collect();
I don't have a problem... except that I want your tutorial to continue! You have good pacing and teach through experience, which is the best way to learn IMO. Anyway, keep doing what you're doing!
This is caused by sdl2_image
and our crate requiring different versions of sdl2
. See xsleonard/rust-sdl2_image#65.
One solution is not to allow a higher minor version than the one we specified, using sdl2_image = "=1.0.0"
.
I'm getting this error trying to install the 1.0.0 version of sdl2_image you've referenced.
no matching package named `sdl2_image` found (required by `arcade-rs`)
location searched: registry https://github.com/rust-lang/crates.io-index
version required: ^1.0.0
versions found: 0.16.0, 0.7.0, 0.6.0, ...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.