Skip to content

Commit

Permalink
Use failure crate for error handling in examples/animation.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Helfet committed Nov 18, 2019
1 parent 29d2632 commit 838002e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ version = ">= 1.0, <= 1.3"
optional = true

[dev-dependencies]
failure = "0.1.6"
rand = "^0.7"

[features]
Expand Down
12 changes: 7 additions & 5 deletions examples/animation.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
extern crate failure;
extern crate sdl2;

use std::path::Path;

use failure::Error;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::rect::Rect;
use sdl2::rect::Point;
use std::time::Duration;

fn main() -> Result<(), String> {
fn main() -> Result<(), Error> {
let sdl_context = sdl2::init()?;
let video_subsystem = sdl_context.video()?;

let window = video_subsystem.window("SDL2", 640, 480)
.position_centered().build().map_err(|e| e.to_string())?;
.position_centered().build()?;

let mut canvas = window.into_canvas()
.accelerated().build().map_err(|e| e.to_string())?;
.accelerated().build()?;
let texture_creator = canvas.texture_creator();

canvas.set_draw_color(sdl2::pixels::Color::RGBA(0,0,0,255));
Expand All @@ -27,8 +30,7 @@ fn main() -> Result<(), String> {
// animation sheet and extras are available from
// https://opengameart.org/content/a-platformer-in-the-forest
let temp_surface = sdl2::surface::Surface::load_bmp(Path::new("assets/characters.bmp"))?;
let texture = texture_creator.create_texture_from_surface(&temp_surface)
.map_err(|e| e.to_string())?;
let texture = texture_creator.create_texture_from_surface(&temp_surface)?;

let frames_per_anim = 4;
let sprite_tile_size = (32,32);
Expand Down

0 comments on commit 838002e

Please sign in to comment.