CdrTomalak

Member
  • Content count

    99
  • Joined

  • Last visited

Community Reputation

272 Neutral

About CdrTomalak

  • Rank
    Member
  1. I'm trying to fade out my sprites in my 2d game using SlimDX. I've noted how it's done in XNA (http://www.xnadevelopment.com/tutorials/fadeinfadeout/FadeInFadeOut.shtml), but how would I do it in SlimDX?   I'm using SpriteTextRenderer as my sprite batch renderer class, which accepts a Color4 (with alpha) as a parameter to the Draw() method, but passing Color4(255,255,255,255) does not result in a full brightness non-faded sprite, so I'm doing something wrong clearly.   Any ideas?
  2. I have put together a basic sound handler class for use in my game. It uses OpenAL. It's a simple method at the moment to play sounds - here's an extract from a switch block: case "EATEN_PILL": wavPath = "D:\\Programming\\SFX\\EATEN_PILL\\Hit_43.wav"; ALfilename = Path.Combine(Path.Combine("Data", "Audio"), wavPath); sound_data = LoadWave(File.Open(ALfilename, FileMode.Open), out channels, out bits_per_sample, out sample_rate); buffer_EATEN_PILL = AL.GenBuffer(); AL.BufferData(buffer_EATEN_PILL, GetSoundFormat(channels, bits_per_sample), sound_data, sound_data.Length, sample_rate); AL.Source(source, ALSourcei.Buffer, buffer_EATEN_PILL); AL.SourcePlay(source); break; Problems: 1. An annoying click at the end of each sound. 2. Eventually sound stops playing completely. This is after perhaps playing 100 sounds.   Has anyone hit this problem before?  
  3. NAudio problems.

    Thanks for the heads up on that.   I've read that thread and it's exactly the problem I'm getting.   Mark has suggested I look at his blog so I'm going to give that a go now.
  4. NAudio problems.

      It calls the Play() method of the WaveOutEvent object, which plays a sound in a new thread.     Not sure what property is being referred to. Can you clarify?
  5. NAudio problems.

    Hi, I have coded two methods of audio into my game engine based on NAudio. Create a WaveOutEvent object every time a sound needs to be be played. Create arrays of WaveOutEvent objects already initialised to play certain sounds. The play method checks the array to detect the first player in the array which is not stopped, and plays it. Ok, so neither of these work yet. I need some advice! Details on 1: The play sound method uses a string variable 'path', which contains the path of the wav file to be played. if(mode == "SINGLE") { WaveOutEvent wavePlayer1; AudioFileReader file1; wavePlayer1 = new WaveOutEvent(); file1 = new AudioFileReader(path); wavePlayer1.Init(file1); wavePlayer1.Play(); } The sound plays once, but when I attempt to play the second time I get the error "Error: Already allocated calling waveOutOpen". This confuses me since a new WaveOutEvent object local to the block of code is created and played, meaning subsequent objects are new objects - not the same. Is that right? Details on 2: The initialisation code called at the start of the game engine is pretty basic: // Array of players ---------------------------------------- NAudio_EATEN_GHOST_Array = new WaveOutEvent[noOfPlayers]; NAudio_EATEN_PILL_Array = new WaveOutEvent[noOfPlayers]; NAudio_EATEN_POWERPILL_Array = new WaveOutEvent[noOfPlayers]; NAudio_KILLED_BY_GHOST_Array = new WaveOutEvent[noOfPlayers]; AudioFileReader file; for(int i=0;i<NAudio_EATEN_GHOST_Array.Length;i++) { NAudio_EATEN_GHOST_Array[i] = new WaveOutEvent(); file = new AudioFileReader("D:\\Programming\\SFX\\EATEN_GHOST\\Hit_55.wav"); NAudio_EATEN_GHOST_Array[i].Init(file); NAudio_EATEN_PILL_Array[i] = new WaveOutEvent(); file = new AudioFileReader("D:\\Programming\\SFX\\EATEN_PILL\\Hit_43_s.wav"); NAudio_EATEN_PILL_Array[i].Init(file); NAudio_EATEN_POWERPILL_Array[i] = new WaveOutEvent(); file = new AudioFileReader("D:\\Programming\\SFX\\EATEN_POWERPILL\\Hit_49.wav"); NAudio_EATEN_POWERPILL_Array[i].Init(file); NAudio_KILLED_BY_GHOST_Array[i] = new WaveOutEvent(); file = new AudioFileReader("D:\\Programming\\SFX\\KILLED_BY_GHOST\\Hit_72.wav"); NAudio_KILLED_BY_GHOST_Array[i].Init(file); } // Array of players ---------------------------------------- With the players all created, the method to play a sound includes the following code, which again is pretty basic and attempts to use the playback state event: if(mode == "PLAYER_ARRAY") { switch(effectsIn) { case "KILLED_BY_GHOST": // 1. Choose a media player which is not playing. i = 0; do { if(NAudio_KILLED_BY_GHOST_Array[i].PlaybackState != PlaybackState.Stopped) { // Keep looking i++; } else { found = true; } } while( (i<NAudio_KILLED_BY_GHOST_Array.Length) && (!found)); // Now 'i' holds the index of the player which is not playing. // 2. Play effect if(found) { NAudio_KILLED_BY_GHOST_Array[i].Play(); } break; case "EATEN_PILL": // 1. Choose a media player which is not playing. i = 0; do { MessageBox.Show(NAudio_EATEN_PILL_Array[i].PlaybackState.ToString()); if(NAudio_EATEN_PILL_Array[i].PlaybackState != PlaybackState.Stopped) { // Keep looking i++; } else { found = true; } } while( (i<NAudio_EATEN_PILL_Array.Length) && (!found)); // Now 'i' holds the index of the player which is not playing. // 2. Play effect if(found) { NAudio_EATEN_PILL_Array[i].Play(); } break; case "EATEN_GHOST": // 1. Choose a media player which is not playing. i = 0; do { if(NAudio_EATEN_GHOST_Array[i].PlaybackState != PlaybackState.Stopped) { // Keep looking i++; } else { found = true; } } while( (i<NAudio_EATEN_GHOST_Array.Length) && (!found)); // Now 'i' holds the index of the player which is not playing. // 2. Play effect if(found) { NAudio_EATEN_GHOST_Array[i].Play(); } break; case "EATEN_POWERPILL": // 1. Choose a media player which is not playing. i = 0; do { if(NAudio_EATEN_POWERPILL_Array[i].PlaybackState != PlaybackState.Stopped) { // Keep looking i++; } else { found = true; } } while( (i<NAudio_EATEN_POWERPILL_Array.Length) && (!found)); // Now 'i' holds the index of the player which is not playing. // 2. Play effect if(found) { NAudio_EATEN_POWERPILL_Array[i].Play(); } break; } // switch } In the case of the EATEN_PILL effect, there are 5 WaveOutEvent objects in the array. 5 sounds play successfully (noOfPlayers is 5...), but then no more. The rest of the calls give silence. The message box debug tells me that the sounds never go back to PlaybackState.Stopped. They are always 'PlaybackState.Playing'. But the sound is a second long, so how can this be? In any case both attempts have not worked, and the code is pretty useless. Am I coming from this from the wrong angle? Is there another way to use the cleverness of the API to achieve what I need to? Argh.
  6. Hi, I'm looking to use Naudio for a game I'm making. I've coded a simple initialisation routine, which currently has: IWavePlayer wavePlayer1; AudioFileReader file1; string filename1 = "D:\\Programming\\SFX\\MUSIC\\IN_GAME_1.wav"; wavePlayer1 = new WaveOut(); file1 = new AudioFileReader(filename1); wavePlayer1.Init(file1); Thread thread1 = new Thread(new ThreadStart(wavePlayer1.Play)); thread1.Start(); When I run the game, the wav file plays for maybe half a second, then it stops, and a second later it resumes. If I place System.Threading.Thread.Sleep(5000) immediately after starting the thread, the delay has an additional 5 seconds. This seems to prove that 'thread1.Start();' isn't actually starting the sound in it's own thread at all. Being a bit of a threading and Naudio noob can anyone tell me what I'm doing wrong here? My requirement for the game is to simply have the ability to play several sounds at once. Nothing major. Any ideas? Thanks in advance!
  7. Easy to use c# sound API - thoughts?

    I've had a look at BASS.NET. This still looks like an API where I'd end up writing boiler-plate code to play a sound even.   SDL.NET seems to have terrible support, so if I got stuck I'd be on my own somewhat.   I had a go with Naudio and Xaudio2 a while back and ditched them for WMP.dll, which worked well enough at the time.
  8. Hi All,   I'm grappling with a number of sound API options for c#. My previous implementation using WMP.dll has hit problems of a wierd nature, and so I'm looking at plan B.   Getting irrKlang to work with sharpdevelop is proving futile.   What else can I use? Or more to the point what DO people here actually use for c# sound? I just need the ability to play simultaneous sounds really. Not much.   Thanks in advance!
  9. Threading and sound. Annoying bug.

    Thanks Phil. The only reason I'm using threads is that when I play without a thread all execution waits for the sound to finish. Can you recommend a simple method I could use? I thought that sound playing had to be done via threading due to the wait issue, but I could be very wrong here!
  10. Thanks Iwm! I went through the code and created a view for each texture as part of initialisation. The error has gone away now. I left the game running on 100 lives and it just keeps on going...
  11. Hi,   I've been trying to pin down an annoying performance bug in my C# 2d game engine.   It only occurs when I have sound enabled, and I am trying to figure out what I am doing wrong. I suspect multiple things, since the sound functionality was implemented quite a while ago to achieve basic functionality. At this stage in development it is now a higher priority. I need to resolve it.   When I implemented sound it was after much experimentation with sound APIs. I tried SoundPlayer, MediaPlayer, and WindowsMediaPlayer - with the latter the only one I could get working in an acceptable manner.   My implementation was based around setting up an array of players for each sound I wanted to play. They are all instantiated up-front. The method by which they are used is: 1. Search through player array until you find one which isn't currently playing. 2. Play the sound.   Now for some reason, which I can't figure out, this implementation is causing a wierd problem. I have a method which fires when you die, and from what I can tell this does NOTHING with sound whatsoever. It basically waits 5 seconds before restarting the game. But with sound on the screen flickers for a millisecond, something in sharpdevelop refreshes, and it's as if there is a sudden lag in the game. From a functionality point of view I don't have a problem  - but the performance is unacceptable.   To give you an idea of what I'm doing, here is some code from my sound initialisation method:                 if(soundLibrary=="WindowsMediaPlayer")                 {                                          // Music player                     WMP_Music = new WMPLib.WindowsMediaPlayer(); WMP_Music.settings.autoStart = false;                    WMP_Music.URL = "D:\\Programming\\SFX\\MUSIC\\IN_GAME_1.wav";                                      // Array of players ----------------------------------------                     WMP_EATEN_GHOST_Array = new WMPLib.WindowsMediaPlayer[EATEN_GHOST_noOfPlayers];                     WMP_EATEN_PILL_Array = new WMPLib.WindowsMediaPlayer[EATEN_PILL_noOfPlayers];                     WMP_EATEN_POWERPILL_Array = new WMPLib.WindowsMediaPlayer[EATEN_POWERPILL_noOfPlayers];                     WMP_KILLED_BY_GHOST_Array = new WMPLib.WindowsMediaPlayer[KILLED_BY_GHOST_noOfPlayers];                                              for(int i=0;i<WMP_EATEN_GHOST_Array.Length;i++)                     {                         WMP_EATEN_GHOST_Array[i] = new WMPLib.WindowsMediaPlayer();                         WMP_EATEN_GHOST_Array[i].settings.autoStart = false;                         WMP_EATEN_GHOST_Array[i].URL = "D:\\Programming\\SFX\\EATEN_GHOST\\Hit_55.wav";                                                  WMP_EATEN_PILL_Array[i] = new WMPLib.WindowsMediaPlayer();                         WMP_EATEN_PILL_Array[i].settings.autoStart = false;                         WMP_EATEN_PILL_Array[i].URL = "D:\\Programming\\SFX\\EATEN_PILL\\Hit_43_s.wav";                                                  WMP_EATEN_POWERPILL_Array[i] = new WMPLib.WindowsMediaPlayer();                         WMP_EATEN_POWERPILL_Array[i].settings.autoStart = false;                         WMP_EATEN_POWERPILL_Array[i].URL = "D:\\Programming\\SFX\\EATEN_POWERPILL\\Hit_49.wav";                                                  WMP_KILLED_BY_GHOST_Array[i] = new WMPLib.WindowsMediaPlayer();                         WMP_KILLED_BY_GHOST_Array[i].settings.autoStart = false;                         WMP_KILLED_BY_GHOST_Array[i].URL = "D:\\Programming\\SFX\\KILLED_BY_GHOST\\Hit_55.wav";                     } So with these set up, here's the code which plays the sound: public void PlayPCM_WindowsMediaPlayer_FX(string effectIn) { int i=-1; bool found = false; if(soundEnabled) { switch(effectIn) { case "KILLED_BY_GHOST": // 1. Choose a media player which is not playing. i = 0; do { if(WMP_KILLED_BY_GHOST_Array[i].playState == WMPLib.WMPPlayState.wmppsPlaying) { // Keep looking i++; } else { found = true; } } while( (i<WMP_KILLED_BY_GHOST_Array.Length) && (!found)); // Now 'i' holds the index of the player which is not playing. // 2. Play effect if(found) { Thread thread = new Thread(new ThreadStart( WMP_KILLED_BY_GHOST_Array[i].controls.play )); thread.Start(); } break; case "EATEN_PILL": // 1. Choose a media player which is not playing. i = 0; do { if(WMP_EATEN_PILL_Array[i].playState == WMPLib.WMPPlayState.wmppsPlaying) { // Keep looking i++; } else { found = true; } } while( (i<WMP_EATEN_PILL_Array.Length) && (!found)); // Now 'i' holds the index of the player which is not playing. // 2. Play effect if(found) { Thread thread = new Thread(new ThreadStart( WMP_EATEN_PILL_Array[i].controls.play )); thread.Start(); } break; case "EATEN_GHOST": // 1. Choose a media player which is not playing. i = 0; do { if(WMP_EATEN_GHOST_Array[i].playState == WMPLib.WMPPlayState.wmppsPlaying) { // Keep looking i++; } else { found = true; } } while( (i<WMP_EATEN_GHOST_Array.Length) && (!found)); // Now 'i' holds the index of the player which is not playing. // 2. Play effect if(found) { Thread thread = new Thread(new ThreadStart( WMP_EATEN_GHOST_Array[i].controls.play )); thread.Start(); } break; case "EATEN_POWERPILL": // 1. Choose a media player which is not playing. i = 0; do { if(WMP_EATEN_POWERPILL_Array[i].playState == WMPLib.WMPPlayState.wmppsPlaying) { // Keep looking i++; } else { found = true; } } while( (i<WMP_EATEN_POWERPILL_Array.Length) && (!found)); // Now 'i' holds the index of the player which is not playing. // 2. Play effect if(found) { Thread thread = new Thread(new ThreadStart( WMP_EATEN_POWERPILL_Array[i].controls.play )); thread.Start(); } break; } // switch } // soundEnabled } It's pretty clunky I know, but it worked at the time - well enough anyway. Can anyone see anything which would explain why I get a screen flicker?   My threading expertise is really basic at the moment.   Thanks in advance
  12. Hi,   I've created a 2D game engine, and am now working on a few defects. The most concerning of which is the error:   D3D11_ERROR_TOO_MANY_UNIQUE_VIEW_OBJECTS: There are too many unique view objects (-2005139453)   I've conducted a code review of my graphics methods.   Something I do repeatedly is this, in an example of my game board drawing code: testSRV = new SlimDX.Direct3D11.ShaderResourceView(graphics, SB_spriteTexture_blueBlock); foreach(TileToDraw tile in wallsToDraw_g) { spriteRenderer.Draw(testSRV, tile.origin, new Vector2(rectangleSizeWall.Width,rectangleSizeWall.Height), CoordinateType.Absolute); } testSRV = new SlimDX.Direct3D11.ShaderResourceView(graphics, SB_spriteTexture_pill); foreach(TileToDraw tile in pillsToDraw_g) { spriteRenderer.Draw(testSRV, tile.origin, new Vector2(rectangleSizePill.Width,rectangleSizePill.Height), CoordinateType.Absolute); } So here I'm just drawing walls and pills on the game board (originated from pacman). I'm thinking that I should be doing something with the ShaderResourceView after I've used it - such as disposing it. Having tried this after the first foreach section (for walls) I find that the pills are not getting drawn at all. So I'm scratching my head wondering what next?   Any ideas? I've spent the last few months working on the game engine so I've not looked into the render methods for a loooong time.   Cheers!  
  13. A Full C64 Game - In 2013

    Wow. I've been making my own 2d game engine in C#, which is hard enough - and you've nailed it in what appears to be C64 assembly language. Massive kudos to you. Well impressed!
  14. Controlling game loop speed

    My first game iteration plan includes quick-win options, as the quality of the first game is not supposed to be A1 but server as a learning exercise. I would imagine that the 2nd pass, or phase 2 would include using deltas and doing things correctly. Although I am under no specific deadline, I do want to draw Phase 1 to a close. The next task after controlling game speed is to introduce sound, which I'm placing a higher priority on than a full rework to control game speed correctly. I guess it depends what's on your plan is for the implementation - and they are always pretty individual. I'd favour a patch-up for now. Just a preference though, and I'm sure others will disagree. If I can patch it up for minimal effort and it runs OK from the users point of view then that's fine for now.
  15. Controlling game loop speed

    Well basically I'm trying to slow the game down. The design is quite (read very) primitive really. I'm just starting out and whilst I have a fairly solid game engine, I need to control the speed of the game loop.   Whilst really I should go with an overhaul to bring the design up to speed with best practice (updating movement based on time passed) I thought a quick fix for now would be to regulate the FPS.