From dd8047d45e670f55c68307a9c323def50661007f Mon Sep 17 00:00:00 2001 From: Ong Date: Sun, 30 Oct 2022 02:38:48 +0800 Subject: [PATCH 1/2] Add an 2d example of pixel bevy --- Cargo.toml | 10 +++++++ assets/pixel/bevy_pixel_dark.png | Bin 0 -> 4902 bytes assets/pixel/bevy_pixel_light.png | Bin 0 -> 182 bytes examples/2d/pixel_perfect.rs | 45 ++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 assets/pixel/bevy_pixel_dark.png create mode 100644 assets/pixel/bevy_pixel_light.png create mode 100644 examples/2d/pixel_perfect.rs diff --git a/Cargo.toml b/Cargo.toml index f4c6f3f9f9037..d20859cdd2e3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -262,6 +262,16 @@ description = "Demonstrates transparency in 2d" category = "2D Rendering" wasm = true +[[example]] +name = "pixel_perfect" +path = "examples/2d/pixel_perfect.rs" + +[package.metadata.example.pixel_perfect] +name = "Pixel Perfect" +description = "Demonstrates pixel perfect in 2d" +category = "2D Rendering" +wasm = true + # 3D Rendering [[example]] name = "3d_scene" diff --git a/assets/pixel/bevy_pixel_dark.png b/assets/pixel/bevy_pixel_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..15feaa94603291e41a863169d93bc996dbbe60b7 GIT binary patch literal 4902 zcmeHLYg7~079IozgI46x@=%Gf)fAm%5++XxN+1N(01YUQDrJ&PU~1l(kOW`URtl{` zg(_&ZfJLibAGg?Ath8bgWpTA&i^wgAsA$nDptWGFtvv~-xNiTr*6lyD*36vQk8kh& zoqf*AnSz8k=|oB(1%jZ7u`y9{@XQ5QhMOz6&q~V7fgo2|PEraf$E;L?Nv|d}IF+;; za4K#i)DUF*@#^N(;-Kjh@-7M_g)PNiYp=A-S$rg-usk@YpkrFH{bXo7(dlt0MqFN( zeXF^@Z}p|=KXlioO?dU4u|@IW#^@Q0j*?8-`{lo`ES$db*xjRs3CLG&^1-pcLsS1C zL)xRF7wUZ*sweF`|5lInkK1vR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rh%Z#>m4r&@9EM^X zHO9eIFjt^JU=+udu!1k(!)l&F%|TcK6z3>LLB;CKB&Jj14k!T5AOMa^p%U$qYKtfyqJ`Y}D!Qm=+-@1`vxm z`V;^-<)9W}qzT7Jy(vkr*NAA2l&B6*XM0n_h9@P4Fary_qvJ<!fFM=fl-vJfH6K> z03#f(nx*7oO2G)jkI~I~HEG36ctj?s6jTEm$XN}Q?xgb7r*pAp;SQb4y*Uz!Cu za@TXKf3fdN(&Jxrcb`(6JKm6*?4BIq^#C%O&2n<1_rp@(v=cT%XOVSinzbLQd=1~~ z7wC>&;D+w0D*MmD{7cE?jCbhXUbs5oQ1OR({rA3-<{q>fKfb!Aulek!FU}d~7Iis5 zUBYv`I)SY5r(yWFQ}3mI`)dSLdnV@Af2IRmG6Z#i>%vb3N84%L zVX;#ZIot27+jc7CC-}RxFHWWn^)T1_-o5(Dfgh$sQ#@1Nahpteb9V(L$e3o4&rxN~ zyM86u^oREmU(@2cMpn_ptPhsWyBGYRuPtQe%-X6L@7^5awxY?@T2J)n!e3V1Z4UfuEONZO8@oO0_BIXKwAWyzX(d1p-r-!oKez{zw{!lERJ^Nb47 z>Gb;gdW*$!p{doOav|k$iO~FO?cl=@=oSCjCJ+BfJ(s;{8B@ATD-MYy(5zgFNB)X2HE)I7$tiPN88{%`QM1#d z+og7+PyWZyw7QRuOe}^d6~D*lme9MC=TFIt18rJZln+rLztS&D$INtb|1-Sd V;{Bj+#)E92SV>&e0ddCKzW^A_JtqJF literal 0 HcmV?d00001 diff --git a/assets/pixel/bevy_pixel_light.png b/assets/pixel/bevy_pixel_light.png new file mode 100644 index 0000000000000000000000000000000000000000..f6225fe25eabb74acbc9256f2a4fec01eb28ba21 GIT binary patch literal 182 zcmeAS@N?(olHy`uVBq!ia0vp^4M3d0#0(@?h)lW#q<8{+LR^8ghK9!B!-q>tOPA}i zlmq#UB|(0{3=Yq3qyae*o-U3d9>;$*z3Hx^S(u z={dg%H{z8g?*FLHGW)<{9 literal 0 HcmV?d00001 diff --git a/examples/2d/pixel_perfect.rs b/examples/2d/pixel_perfect.rs new file mode 100644 index 0000000000000..16188d97cdec2 --- /dev/null +++ b/examples/2d/pixel_perfect.rs @@ -0,0 +1,45 @@ +//! Renders a 2D scene containing pixelated bevy logo in pixel perfect + +use bevy::prelude::*; + +fn main(){ + App::new() + .add_plugins(DefaultPlugins) + .add_plugin(ImagePlugin::default_nearest()) + .add_startup_system(setup) + .add_system(sprite_movement) + .run(); +} + +#[derive(Component)] +enum Direction { + Left, + Right, +} + +fn setup(mut commands: Commands, asset_server: Res) { + commands.spawn(Camera2dBundle::default()); + commands.spawn(( + SpriteBundle { + texture: asset_server.load("pixel/bevy_pixel_light.png"), + transform: Transform::from_xyz(100., 0., 0.), + ..default() + }, + Direction::Right, + )); +} + +fn sprite_movement(time: Res