Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Bindings - other languages
»
DotNet
»
Set sprite origin.
Print
Pages: [
1
]
Author
Topic: Set sprite origin. (Read 7064 times)
0 Members and 2 Guests are viewing this topic.
Enok
Newbie
Posts: 16
Set sprite origin.
«
on:
November 20, 2014, 02:41:13 pm »
Hello.
Setting the sprite origin doesn't seem to work.
I can't really see what I'm doing wrong here, everything else works just fine. I can't set the Origin even if I do it directly to the sprite itself, rather than using properties.
public
void
LoadContent
(
)
{
player
.
Origin
=
new
Vector2f
(
player
.
Scale
.
Y
, player
.
Scale
.
Y
)
/
2
;
}
public
Vector2f Origin
{
get
{
return
this
.
sprite
.
Origin
;
}
set
{
this
.
sprite
.
Origin
=
value
;
}
}
«
Last Edit: November 20, 2014, 03:54:03 pm by eXpl0it3r
»
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 11030
Re: Set sprite origin.
«
Reply #1 on:
November 20, 2014, 02:54:16 pm »
And how do you verify that "it doesn't work"?
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
Enok
Newbie
Posts: 16
Re: Set sprite origin.
«
Reply #2 on:
November 20, 2014, 02:57:28 pm »
It doesn't do anything. It doesn't change the origin, nothing happens. There's no difference with or without it. No matter what numbers I type in, the sprites origin is always in the top-left.
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 11030
Re: Set sprite origin.
«
Reply #3 on:
November 20, 2014, 03:01:33 pm »
Provide a complete and minimal example.
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
Enok
Newbie
Posts: 16
Re: Set sprite origin.
«
Reply #4 on:
November 20, 2014, 03:07:24 pm »
This is what it looks like when I just draw the sprite.
This is what it looks like with player.Origin = new Vector2f(50,50);
Game.cs
namespace
PointAndClick
{
class
Game
{
Player player
=
new
Player
(
)
;
public
void
LoadContent
(
)
{
player
.
Texture
=
new
Texture
(
Converter
.
ToSFTexture
(
Resources
.
spr_cannon_barrel
)
)
;
player
.
Origin
=
new
Vector2f
(
50
,
50
)
;
}
//Physics, move stuff.
public
void
FixedUpdate
(
TimeSpan deltaTime
)
{
}
//Draw stuff, check for input
public
void
Update
(
RenderWindow rWindow
)
{
rWindow
.
Clear
(
new
Color
(
25
,
18
,
63
)
)
;
player
.
Draw
(
rWindow
)
;
rWindow
.
Display
(
)
;
}
public
static
void
UnloadContent
(
)
{
}
}
}
Player.cs
namespace
PointAndClick
{
public
class
Player
{
private
Sprite sprite
=
new
Sprite
(
)
;
//Transform
public
Vector2f Position
{
get
{
return
this
.
sprite
.
Position
;
}
set
{
this
.
sprite
.
Position
=
value
;
}
}
public
Vector2f Scale
{
get
{
return
this
.
sprite
.
Scale
;
}
set
{
this
.
sprite
.
Scale
=
value
;
}
}
public
float
Rotation
{
get
{
return
this
.
sprite
.
Rotation
;
}
set
{
this
.
sprite
.
Rotation
=
value
;
}
}
public
Texture Texture
{
get
{
return
this
.
sprite
.
Texture
;
}
set
{
this
.
sprite
.
Texture
=
value
;
}
}
public
Vector2f Origin
{
get
{
return
this
.
sprite
.
Origin
;
}
set
{
this
.
sprite
.
Origin
=
value
;
}
}
public
void
Draw
(
RenderWindow rWindow
)
{
rWindow
.
Draw
(
this
.
sprite
)
;
}
}
}
«
Last Edit: November 20, 2014, 03:54:27 pm by eXpl0it3r
»
Logged
Ztormi
Jr. Member
Posts: 71
Web developer by day. Game developer by night.
Re: Set sprite origin.
«
Reply #5 on:
November 20, 2014, 04:24:44 pm »
^^ Works fine.
(click to show/hide)
public
class
Player
{
private
Sprite sprite
=
new
Sprite
(
)
;
//Transform
public
Vector2f Position
{
get
{
return
this
.
sprite
.
Position
;
}
set
{
this
.
sprite
.
Position
=
value
;
}
}
public
Vector2f Scale
{
get
{
return
this
.
sprite
.
Scale
;
}
set
{
this
.
sprite
.
Scale
=
value
;
}
}
public
float
Rotation
{
get
{
return
this
.
sprite
.
Rotation
;
}
set
{
this
.
sprite
.
Rotation
=
value
;
}
}
public
Texture Texture
{
get
{
return
this
.
sprite
.
Texture
;
}
set
{
this
.
sprite
.
Texture
=
value
;
}
}
public
Vector2f Origin
{
get
{
return
this
.
sprite
.
Origin
;
}
set
{
this
.
sprite
.
Origin
=
value
;
}
}
public
void
Draw
(
RenderWindow rWindow
)
{
rWindow
.
Draw
(
this
.
sprite
)
;
}
}
public
static
class
Program
{
private
static
Player p
=
new
Player
(
)
;
private
static
readonly
Color CornflowerBlue
=
new
Color
(
100
,
149
,
237
)
;
public
static
void
Main
(
string
[
]
args
)
{
RenderWindow window
=
new
RenderWindow
(
new
VideoMode
(
1280
,
720
)
,
"SFML Window"
)
;
window
.
Closed
+=
(
sender, eventArgs
)
=>
window
.
Close
(
)
;
LoadContent
(
)
;
while
(
window
.
IsOpen
(
)
)
{
window
.
DispatchEvents
(
)
;
window
.
Clear
(
CornflowerBlue
)
;
p
.
Draw
(
window
)
;
window
.
Display
(
)
;
}
}
public
static
void
LoadContent
(
)
{
p
.
Texture
=
new
Texture
(
"marsu.jpg"
)
;
p
.
Origin
=
new
Vector2f
(
-
100
,
-
100
)
;
}
}
«
Last Edit: November 20, 2014, 04:28:25 pm by Ztormi
»
Logged
Enok
Newbie
Posts: 16
Re: Set sprite origin.
«
Reply #6 on:
November 20, 2014, 05:25:45 pm »
The hell.. I'm gonna compile the latest source and try again..
Logged
Print
Pages: [
1
]
SFML community forums
»
Bindings - other languages
»
DotNet
»
Set sprite origin.
anything