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
»
C# Port for Particle system example
Print
Pages: [
1
]
Author
Topic: C# Port for Particle system example (Read 5598 times)
0 Members and 1 Guest are viewing this topic.
Optimistic
Newbie
Posts: 14
C# Port for Particle system example
«
on:
November 09, 2017, 03:06:32 am »
I have taken the code from
https://www.sfml-dev.org/tutorials/2.4/graphics-vertex-array.php
at the bottom of the page and translated it into its C# equivalent, but I can't seem to find the error; it doesn't output anything to the screen, and it is just black (The screen clear is black).
https://pastebin.com/pF40bKaA
is where I have pasted my code.
I am sorry for any stupid mistakes I made in the "translation" as though I know basically nothing about C++ in specific. Thanks!
«
Last Edit: November 21, 2017, 11:01:46 pm by Optimistic
»
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 11030
Re: C# Port for Particle system example
«
Reply #1 on:
November 09, 2017, 08:18:52 am »
How fast does your particle alpha value reach 0?
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
Optimistic
Newbie
Posts: 14
Re: C# Port for Particle system example
«
Reply #2 on:
November 09, 2017, 01:23:01 pm »
Not sure, will have to test later in the day. Thanks.
Logged
Optimistic
Newbie
Posts: 14
Re: C# Port for Particle system example
«
Reply #3 on:
November 09, 2017, 11:56:51 pm »
Ok, just tested, and found out that the alpha value goes from 255 to 0 in the first frame. Might it be because of the statement on line 97 because of ratio being to small?
Logged
Optimistic
Newbie
Posts: 14
Re: C# Port for Particle system example
«
Reply #4 on:
November 11, 2017, 10:04:07 pm »
I rewrote the update function to be more readable, here is the new code:
public
void
Update
(
Time Elapsed, Random R
)
{
uint
count
=
0
;
foreach
(
var
b
in
m_particles
)
{
var
temp
=
m_vertices
[
count
]
;
b
.
lifetime
-=
Elapsed
;
if
(
b
.
lifetime
<=
Time
.
FromSeconds
(
0
)
)
{
float
Angle
=
(
(
R
.
Next
(
)
%
360
)
*
3
.
14159f
)
/
180
;
float
Speed
=
(
(
R
.
Next
(
)
%
50
)
+
50
)
;
b
.
velocity
=
new
Vector2f
(
(
float
)
Math
.
Cos
(
Angle
)
*
Speed,
(
float
)
Math
.
Sin
(
Angle
)
*
Speed
)
;
b
.
lifetime
=
Time
.
FromMilliseconds
(
(
R
.
Next
(
)
%
2000
)
+
1000
)
;
temp
.
Color
=
Color
.
White
;
temp
.
Position
=
m_emitter
;
}
temp
.
Position
+=
b
.
velocity
*
Elapsed
.
AsSeconds
(
)
;
float
ratio
=
b
.
lifetime
.
AsSeconds
(
)
/
m_lifetime
.
AsSeconds
(
)
;
temp
.
Color
.
A
=
255
;
m_vertices
[
count
]
=
temp
;
}
}
Logged
Optimistic
Newbie
Posts: 14
Re: C# Port for Particle system example
«
Reply #5 on:
November 18, 2017, 11:10:37 pm »
Any Ideas? Anyone?
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 11030
Re: C# Port for Particle system example
«
Reply #6 on:
November 19, 2017, 01:11:45 am »
Any ideas on what? You already found the issue, is it really too much asked of you to find out how the logic of your code works?
If you don't understand it, then sit down with a pen and paper and play through your code manually.
Alternatively you can just start the debugger and step through the code.
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
Optimistic
Newbie
Posts: 14
Re: C# Port for Particle system example
«
Reply #7 on:
November 21, 2017, 12:47:48 am »
Oh goodness how stupid I am....
I use an unused variable named count, and not the iterator index...
Wow...
Logged
Optimistic
Newbie
Posts: 14
Re: C# Port for Particle system example
«
Reply #8 on:
November 21, 2017, 12:55:16 am »
A Cleaned up and working version is available at
https://pastebin.com/3bXMX8in
Logged
Print
Pages: [
1
]
SFML community forums
»
Bindings - other languages
»
DotNet
»
C# Port for Particle system example
anything