XNA SoundEffects not playing - audio

Followed a few tutorials and I'm having no luck, I'm trying to add a simple .WAV sound effect into XNA using free samples, I have named the sound as:
SoundEffect hit1;
SoundEffect hit2;
And then loaded the content with:
hit1= content.load<SoundEffect>("hit1")
But when it comes to adding the play to a button press and I go to test it there's no sound at all even no errors or nothing the game loads and is playable but any sound effects are not working.
** // Sounds
SoundEffect hit1;
SoundEffect hit2;
This is my variable names:
// Sounds
hit1 = Content.Load<SoundEffect>("hit1");
hit2 = Content.Load<SoundEffect>("hit2");
This is how I'm loading them in the loadcontent method:
//If Keyboard Key W is Pressed or Buttong Y
if (keys1.IsKeyDown(Keys.W) && oldKeys1.IsKeyUp(Keys.W)
|| (oldpad1.Buttons.Y == ButtonState.Released) && (pad1.Buttons.Y == ButtonState.Pressed))
{
secondsPassed = 0;
// IF The Target Image is a Gnome
if (targets[0] == sprites[0])
{
//They whacked a gnome
GnomeHits = GnomeHits + 1;
runNum = 0;
secondsPassed = 0;
hit1.Play();
}
else
{
//They whacked a troll
scoreNum = scoreNum + 1;
runNum = runNum + 1;
GnomeHits = 0;
secondsPassed = 0;
hit2.Play();
}
SetUpSpriteLoop();
And this is one of the control buttons I'm trying to assign sound too
when I hit F5 and run the game when I hit the key or button no sound at all.

I had a similar problem with Monogame (built from XNA's ashes) on a Windows 10 machine. I fixed it by reinstalling DirectX, and everything just worked.

My first recommendation would be to make sure you are updating the keyboard presses. I only say that as I can't see you doing that in your code. If you do not do this then the key states will not update and therefore you will never enter the if statement.
Once you have ensured you are entering the if statement, I would play around with the volume of the sound effect to make sure it is actually audible. I may be a bit off base there however if I am I suggest following this tutorial rbwhitaker is a great resource for XNA.

Related

Can this code be changed to support a preview in the print dialog?

I am not sure if this is an issue that can be resolved with coding or is by design. I am running the latest version of Windows 11 with all updates. And my application is a MFC dialog application built with Visual Studio 2022.
My application uses a CHtmlView control and the user can trigger a Print Preview. This event will trigger the following code:
void CChristianLifeMinistryHtmlView::DoPrintPreview()
{
ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, nullptr, nullptr);
HWND HWND_PP = nullptr ;
const auto t1 = ::GetTickCount64();
auto t2 = ::GetTickCount64(); // Extra line required for 'while' rearrangement.
while (HWND_PP == nullptr && t2 - t1 <= 6000) // if found or Timeout reached...
{
HWND HWND_FG = ::GetForegroundWindow(); // Get the ForeGroundWindow
if (HWND_FG != nullptr)
{
TCHAR szClassName[256]{} ;
::GetClassName(HWND_FG, &szClassName[0], 256);
if (lstrcmp(&szClassName[0], IE_PPREVIEWCLASS) == 0) // Check for Print Preview Dialog
HWND_PP = HWND_FG ;
}
theApp.PumpMessage();
t2 = ::GetTickCount64();
}
if (HWND_PP != nullptr)
{
RECT workArea{};
::SystemParametersInfo( SPI_GETWORKAREA, 0, &workArea, 0 );
::MoveWindow(HWND_PP, workArea.left, workArea.top,
workArea.right - workArea.left, workArea.bottom - workArea.top, TRUE);
}
}
This code works fine, and I get a good print preview, resized to the display. For example:
Now, if I hit Print from here it displays:
Opting to print to PDF looks the same:
Prior to the recent Windows 11 Updates these latter "print dialogs" looked different with no preview anyway. But since this updated version of the system "print dialog" can cope with a preview, is there no way to get our existing CHtmlView preview displayed there?
This is only a cosmetic thing because I have a standard preview for the user to see anyway (snap 1). But it would be the icing on the cake if that preview could someone be fed into this popup print window.
Is this something we can do by code or is it a "system / by design issue"?

NSSplitViewItem collapse animation and window setFrame conflicting

I am trying to make a (new in 10.10) NSSplitViewItem collapse and uncollapse whilst moving its containing window so as to keep the whole thing "in place".
The problem is that I am getting a twitch in the animation (as seen here).
The code where I'm doing the collapsing is this:
func togglePanel(panelID: Int) {
if let splitViewItem = self.splitViewItems[panelID] as? NSSplitViewItem {
// Toggle the collapsed state
NSAnimationContext.runAnimationGroup({ context in
// special case for the left panel
if panelID == 0 {
var windowFrame = self.view.window.frame
let panelWidth = splitViewItem.viewController.view.frame.width
if splitViewItem.collapsed {
windowFrame.origin.x -= panelWidth
windowFrame.size.width += panelWidth
} else {
windowFrame.origin.x += panelWidth
windowFrame.size.width -= panelWidth
}
self.view.window.animator().setFrame(windowFrame, display: true)
}
splitViewItem.animator().collapsed = !splitViewItem.collapsed
}, completionHandler: nil)
}
}
I am aware of the "Don't cross the streams" issue (from session 213, WWDC'13) where a window resizing animation running on the main thread and a core animation collapse animation running on a separate thread interfere with each other. Putting the splitViewItem collapse animation onto the main thread seems like the wrong approach and I've got a nagging feeling there's a much better way of doing this that I'm missing.
Since I am not finding any documentation on the NSSplitViewItems anywhere (yet) I would appreciate any insights on this.
I have the little test project on GitHub here if anyone wants a look.
Update The project mentioned has now been updated with the solution.
Thanks,
Teo
The problem is similar to the "don't cross the streams" issue in that there are two drivers to the animation you've created: (1) the split view item (2) the window, and they're not in sync.
In the example from the '13 Cocoa Animations talk, constraints were setup to result in the correct within-window animation as only the window's frame was animated.
Something similar could be tried here -- only animating the window's frame and not the split view item, but since the item manages the constraints used to (un)collapse, the app can't control exactly how within-window content animates:
Instead the split view item animation could completely drive the animation and use NSWindow's -anchorAttributeForOrientation: to describe how the window's frame is affected.
if let splitViewItem = self.splitViewItems[panelID] as? NSSplitViewItem {
let window = self.view.window
if panelID == 0 {
// The Trailing edge of the window is "anchored", alternatively it could be the Right edge
window.setAnchorAttribute(.Trailing, forOrientation:.Horizontal)
}
splitViewItem.animator().collapsed = !splitViewItem.collapsed
}
For anyone using Objective C and targeting 10.11 El Capitan.
This did the trick for me, didn't need to set AnchorAttributes.
splitViewItem.collapsed = YES;

How do I get a Plymouth sprite to rotate?

I'm working on a custom Plymouth splash for Kubuntu. I'm attempting to make an image rotate as the system is loading. I have tested it using both reboots and the X11 plugin and have been unsuccessful in both. Here's the .script file:
spiral_image = Image("Splash.png");
spiral_sprite = Sprite(spiral_image);
spiral_sprite.SetX(window.GetWidth() /2 - spiral_image.GetWidth() /2);
spiral_sprite.SetY(window.GetHeight() /2 - spiral_image.GetHeight() /2);
fun refresh_callback ()
{
time++;
theta = time / 100;
spiral_sprite.Rotate(theta);
}
Plymouth.SetRefreshFunction (refresh_callback);
You need to rotate the image, not the sprite:
fun refresh_callback () {
time++;
theta = time / 100;
spiral_sprite.SetImage( spiral_image.Rotate(theta) );
}
As per official documentation, in case anyone finds this question before they manage to find Plymouth documentation.
(Extra notes, slightly off-topic: Documentation says that default text colour is white. Don't count on that too much, it's black.)

Flash shared object always gets reset

So in my game, you want to make the potato as big as possible. The first time you play it, the highscores work fine,giving you a highscore and saving it. The problem is that whenever you play the game, the highscore is always reset to your current score, which means that even if you get a lower score then your previous highscore, it saves your current score as the highscore. my code looks like this:
var savedstuff:SharedObject = SharedObject.getLocal("myStuff");
if (savedstuff.data.bestScore = 0) {
savedstuff.data.bestScore = 1
}
bigness.text = finish.toString();
if (finish > savedstuff.data.bestScore){
savedstuff.data.bestScore = finish;
}
best.text = savedstuff.data.bestScore.toString();
savedstuff.flush();
where bigness is a textbox displaying your current score, best is a textbox displaying your highscore and bestScore is where the best score is stored. I have the line "if (finish > savedstuff.dada.bestScore)" which should make the overwrite only occur if you get a higher score, but it seems to just ignore that line. my game is here
http://www.kongregate.com/games/pwnedcat/grow-a-potato
any help is appreciated. I just started flash so I really don't know anything. :(
Check the condition, it should be
savedstuff.data.bestScore == 0
Instead of
savedstuff.data.bestScore = 0

LWJGL Fullscreen not working

I'm trying to add fullscreen functionality to my program but I couldn't get it to work. I'm trying
Display.setFullscreen(true);
I tried changing its position to above where I create the display or where I set the displaymode, but still not working. Any help about this?
From my experience the DisplayMode needs to support it. You can try this:
DisplayMode displayMode = null;
DisplayMode[] modes = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++)
{
if (modes[i].getWidth() == width
&& modes[i].getHeight() == height
&& modes[i].isFullscreenCapable())
{
displayMode = modes[i];
}
}
After doing this your Display.setFullscreen(true) should work
I know this question is quite (5 years) old, but there may still be people looking for a solution to this question.
The simplest way is to do:
Display.setDisplayModeAndFullscreen(Display.getDesktopDisplayMode());
Which will put your display in fullscreen for you. No need for setFullscreen() with this either.

Resources