Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6679311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:20:41+00:00 2026-05-26T04:20:41+00:00

I’m trying to do an app where a short sound sample is supposed to

  • 0

I’m trying to do an app where a short sound sample is supposed to be played while the person using the app is dragging his/her finger(s) across the screen. When the finger(s) are lifted away from the screen – the sound will stop.

This is the current function that triggers the sound (I’ve tried various methods):

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{

NSLog(@"Ja, den börjar...");
return YES; 
}

-(void)ccTouchMoved:(NSSet *)touch withEvent:(UIEvent *)event{

    soundFile = [[CDAudioManager sharedManager] audioSourceForChannel:kASC_Right];
    [soundFile load:@"sound.wav"];
    soundFile.backgroundMusic = NO;
    soundSourceForFile:@"sound.wav"]retain];
}

This is the function that stops the sound:

-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{
    [soundFile stop]; 
}

I first started out using the ccTouchBegan (Just to get some kind of sound working), which looped the sound seamlessly. At this point the ccTouchEnded worked together with the “Touch Up Inside” event.

The point, as I said, is the the sound is supposed to be played when the user drags his/her finger(s) across the screen. But when I tried to the tie the playSound function to the “ccTouchMoved” the sound loops repeatedly over itself, instead of one at the time, making it hell to use. The stopSound function doesn’t work after i changed to the ccTouchMoved.

I tried to use NSTimer to create some kind of way to handle the loops, but without any success.

I started this project with the regular iOS SDK, and found my limitations when i found out i wasn’t able to handle pitch & gain manipulation without Cocos2d.

I got everything working in the regular SDK by wrapping it in a if-statement:

if(![mySound isPlaying]{
    [mySound play];
}

This, as I said, worked perfectly fine in the regular SDK, but not now when I’m using Cocos2d.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:20:41+00:00Added an answer on May 26, 2026 at 4:20 am

    ccTouchMoved will be called continuously as the finger moves along the screen. The problem you are having here is that each time this is called you are loading a new sound file and they are overlapping because they are newly created individual objects. You only have a reference to the final sound you load (which is what soundFile is pointing at) and you aren’t freeing up the memory either.

    Example:

    (as you drag your finger)

    LoadedSoundA created and starts playing
    soundfile points to LoadedSoundA
    // finger moves
    LoadedSoundB created and starts playing
    soundfile points to LoadedSoundB
    // finger moves
    LoadedSoundC created and starts playing
    soundfile points to LoadedSoundC
    ... etc
    

    the only sound you have a pointer to at the moment is the last created sound, since you reassign soundfile each time. So you can only ‘stop’ the sound you created last.

    You are also leaking a lot of memory since you are retaining all of these sounds and never releasing them.

    I would suggest a different tactic:

    In touchesBegan you should load the sound and have it play on loop and record the time of the touch into a class level iVar.

    Now, in TouchesMoved you should get the time of the current touch and see if it is close enough to the time you recorded. If it is within say, 0.5 seconds then just update the recorded timestamp and continue; However, if it has been too long since the last touch you stop the sound that is playing.

    This way you have a seamless sound being played, it is only created once and you maintain your ownership of it.

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.