Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
General
»
General discussions
»
Multiple IntRects in a single Sprite
Print
Pages: [
1
]
Author
Topic: Multiple IntRects in a single Sprite (Read 3997 times)
0 Members and 1 Guest are viewing this topic.
escape
Newbie
Posts: 1
Multiple IntRects in a single Sprite
«
on:
June 15, 2020, 08:42:27 pm »
I'm trying to do level gen but I want to have a single sprite for the level. I have a sprite sheet and i would like to assign different textures to different "areas" of a sprite.
sprite.
setTextureRect
(
sf
::
IntRect
(
0
,
0
,
32
,
32
)
)
;
sprite.
setTextureRect
(
sf
::
IntRect
(
32
,
32
,
32
,
32
)
)
;
The code above I know would replace the texture rect but is there a way that I can have both?
Logged
Hapax
Hero Member
Posts: 3379
My number of posts is shown in hexadecimal.
Re: Multiple IntRects in a single Sprite
«
Reply #1 on:
June 15, 2020, 08:50:36 pm »
A sprite is a single area of a texture but there are ways to draw multiple areas at once.
The first - and probably easiest - way is to just have multiple sprites with one for each area of the texture.
The second is more powerful but a bit more complex: vertex array.
The idea here is that each quad can have its own area of a texture. With a vertex array, you can have multiple quads as one object (a single draw call and all transformations apply to all quads together).
Take a look at the
vertex array tutorial
to see how it works.
Specifically, take extra note of
the tile map example part
.
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
G.
Hero Member
Posts: 1593
Re: Multiple IntRects in a single Sprite
«
Reply #2 on:
June 15, 2020, 08:52:23 pm »
Yes, what Hapax said.
However if for some weird reason you want to draw everything with the same sprite, you can set the texture rect, draw, set a different texture rect, draw, etc.
Logged
Print
Pages: [
1
]
SFML community forums
»
General
»
General discussions
»
Multiple IntRects in a single Sprite
anything