Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kayak UI
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Forks
Kayak UI
Commits
ac87e79f
Commit
ac87e79f
authored
3 years ago
by
Matthew
Browse files
Options
Downloads
Patches
Plain Diff
Added texture atlas example
parent
33b239af
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/texture_atlas.rs
+84
-0
84 additions, 0 deletions
examples/texture_atlas.rs
with
84 additions
and
0 deletions
examples/texture_atlas.rs
0 → 100644
+
84
−
0
View file @
ac87e79f
use
bevy
::{
prelude
::{
App
as
BevyApp
,
AssetServer
,
Commands
,
Handle
,
Res
,
ResMut
},
window
::
WindowDescriptor
,
DefaultPlugins
,
};
use
kayak_core
::
styles
::
PositionType
;
use
kayak_ui
::
bevy
::{
BevyContext
,
BevyKayakUIPlugin
,
ImageManager
,
UICameraBundle
};
use
kayak_ui
::
core
::{
render
,
styles
::{
Style
,
StyleProp
,
Units
},
Index
,
};
use
kayak_ui
::
widgets
::{
App
,
TextureAtlas
};
fn
startup
(
mut
commands
:
Commands
,
asset_server
:
Res
<
AssetServer
>
,
mut
image_manager
:
ResMut
<
ImageManager
>
,
)
{
commands
.spawn_bundle
(
UICameraBundle
::
new
());
let
image_handle
:
Handle
<
bevy
::
render
::
texture
::
Image
>
=
asset_server
.load
(
"texture_atlas.png"
);
let
ui_image_handle
=
image_manager
.get
(
&
image_handle
);
//texture_atlas.png uses 16 pixel sprites and is 272x128 pixels
let
tile_size
=
16
;
let
columns
=
272
/
tile_size
;
let
rows
=
128
/
tile_size
;
let
atlas
=
bevy
::
sprite
::
TextureAtlas
::
from_grid
(
image_handle
,
bevy
::
prelude
::
Vec2
::
splat
(
tile_size
as
f32
),
columns
,
rows
);
//The sign in the top right of the image would be index 16
let
sign_index
=
16
;
//The flower is in the 6(-1) row and 15 collumn
let
flower_index
=
columns
*
5
+
15
;
let
context
=
BevyContext
::
new
(|
context
|
{
let
atlas_styles
=
Style
{
position_type
:
StyleProp
::
Value
(
PositionType
::
ParentDirected
),
width
:
StyleProp
::
Value
(
Units
::
Pixels
(
200.0
)),
height
:
StyleProp
::
Value
(
Units
::
Pixels
(
200.0
)),
..
Style
::
default
()
};
let
rect
=
atlas
.textures
[
sign_index
];
let
sign_position
=
rect
.min
;
let
sign_size
=
rect
.max
-
rect
.min
;
let
rect
=
atlas
.textures
[
flower_index
];
let
flower_position
=
rect
.min
;
let
flower_size
=
rect
.max
-
rect
.min
;
render!
{
<
App
>
<
TextureAtlas
styles
=
{
Some
(
atlas_styles
)}
handle
=
{
ui_image_handle
}
position
=
{(
sign_position
.x
,
sign_position
.y
)}
tile_size
=
{(
sign_size
.x
,
sign_size
.y
)}
/>
<
TextureAtlas
styles
=
{
Some
(
atlas_styles
)}
handle
=
{
ui_image_handle
}
position
=
{(
flower_position
.x
,
flower_position
.y
)}
tile_size
=
{(
flower_size
.x
,
flower_size
.y
)}
/>
</
App
>
}
});
commands
.insert_resource
(
context
);
}
fn
main
()
{
BevyApp
::
new
()
.insert_resource
(
WindowDescriptor
{
width
:
1270.0
,
height
:
720.0
,
title
:
String
::
from
(
"UI Example"
),
..
Default
::
default
()
})
.add_plugins
(
DefaultPlugins
)
.add_plugin
(
BevyKayakUIPlugin
)
.add_startup_system
(
startup
)
.run
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment