i'm trying create new class fadablesoundeffectinstance
, inherits soundeffectinstance
.
my fadablesoundeffectinsance
allow soundeffectinstances
easlily faded in , out, after finishing class, rewarded lovely error here:
the type 'microsoft.xna.framework.audio.soundeffectinstance' has no constructors defined
after while of research , digging xna source, found this.
internal soundeffectinstance(soundeffect parenteffect, bool fireandforget) { ... }
so have constructor, cannot access it.
how can work around able create class?
note people have not used xna before, not create new class blah = new soundeffectinstance
instead load soundeffect
, use method createinstance()
. also, soundeffect
sealed class. also, adding constructor new class throw same error, soundeffectinstance
instead.
here relevant code incase need in depth
fadablesoundeffectinstance
public sealed class fadablesoundeffectinstance : soundeffectinstance { public float fadespeed = .01f; public audiofadestate fadestate = audiofadestate.normal; public void fadeout() { //logic } public void fadein() { //logic } public void update(gametime gametime) { //logic } }
and extension method can call soundeffect.createfadableinstance()
public static fadablesoundeffectinstance createfadableinstance(this soundeffect soundeffect) { return (fadablesoundeffectinstance)soundeffect.createinstance(); }
your question not unique.
don't have access constructor, can't create derived class. same whether use xna or not.
if want use new sound effect directly, can create pseudo-decorator, takes in actual soundeffectinstance
, wraps it.
however, doesn't if want pass sound effect xna methods want soundeffectinstance
.
Comments
Post a Comment