Help with piano app

madScreenz

  • Posts: 9
Hi, I am trying to start with a simple app like a piano game. I made keys as separate actors, uploaded all the sounds, created actor behaviors using the puzzle code - (When the mouse is pressed on actor  [play sound 1]) - attached the behavior to the proper key and attached it to the scene.

When I test it I get a piano app with bugs.
1. I can't get two sounds by clicking two keys, only one sound at a time
2. Something weird happens - when I press one key I get the right sound. When I press another key I get the previous sound. The next time I press the same key I get the proper sound.

Does anyone have any idea what is going on and how to code properly?

Thanks much, any help would be greatly appreciated.

LIBERADO

  • *
  • Posts: 2720
1. I can't get two sounds by clicking two keys, only one sound at a time
To get polyphony, you can play each sound on a different channel.
Use this block:
There are 32 channels available. (from 0 to 31)
   
Also, if your game will be played on touch screens, the detection of simultaneous multiple touches requires the Multi-Touch feature: http://www.stencyl.com/help/view/mobile-input/

Quote
2. Something weird happens - when I press one key I get the right sound. When I press another key I get the previous sound. The next time I press the same key I get the proper sound.
We need to see a screenshot of your code to know where the error is.

« Last Edit: July 18, 2017, 07:03:51 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

madScreenz

  • Posts: 9
Thanks so much for the quick reply! I can place each note on a separate channel but I am getting the same inconsistent note played problem. I will try to create a new project from scratch to make sure nothing was messed up. I'm just using those blocks of code - how do I send you the code to debug? Hopefully redoing the project will fix it but can't be sure yet

LIBERADO

  • *
  • Posts: 2720
You can take and save a screenshot of your code by clicking on the camera icon in the lower right corner of the Stencyl interface. Also, you could export your game by using the option: File > Export Game...
Then, you can attach it to a post in this forum.

« Last Edit: July 18, 2017, 07:04:45 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

madScreenz

  • Posts: 9
Hi again, I built it again carefully using only 2 notes and unfortunately adding the separate channels did not allow simultaneous notes. And again, I have the same weird problem - the first time I press a key I get no sound. When I press the other key I get the wrong sound. Here is the only code I am using: when the mouse is pressed on actor: play sound1 on channel 1.  Then I attach the behavior to the key and the scene.
Is there something else I need?

madScreenz

  • Posts: 9
sorry, I didn't see the last post. Here is the exported app with 2 keys. It seems to work but when you play around with it you'll notice something isn't right. I really appreciate your time and help!!!

madScreenz

  • Posts: 9
package scripts;

import com.stencyl.graphics.G;
import com.stencyl.graphics.BitmapWrapper;

import com.stencyl.behavior.Script;
import com.stencyl.behavior.Script.*;
import com.stencyl.behavior.ActorScript;
import com.stencyl.behavior.SceneScript;
import com.stencyl.behavior.TimedTask;

import com.stencyl.models.Actor;
import com.stencyl.models.GameModel;
import com.stencyl.models.actor.Animation;
import com.stencyl.models.actor.ActorType;
import com.stencyl.models.actor.Collision;
import com.stencyl.models.actor.Group;
import com.stencyl.models.Scene;
import com.stencyl.models.Sound;
import com.stencyl.models.Region;
import com.stencyl.models.Font;
import com.stencyl.models.Joystick;

import com.stencyl.Engine;
import com.stencyl.Input;
import com.stencyl.Key;
import com.stencyl.utils.Utils;

import openfl.ui.Mouse;
import openfl.display.Graphics;
import openfl.display.BlendMode;
import openfl.display.BitmapData;
import openfl.display.Bitmap;
import openfl.events.Event;
import openfl.events.KeyboardEvent;
import openfl.events.TouchEvent;
import openfl.net.URLLoader;

import box2D.common.math.B2Vec2;
import box2D.dynamics.B2Body;
import box2D.dynamics.B2Fixture;
import box2D.dynamics.joints.B2Joint;

import motion.Actuate;
import motion.easing.Back;
import motion.easing.Cubic;
import motion.easing.Elastic;
import motion.easing.Expo;
import motion.easing.Linear;
import motion.easing.Quad;
import motion.easing.Quart;
import motion.easing.Quint;
import motion.easing.Sine;

import com.stencyl.graphics.shaders.BasicShader;
import com.stencyl.graphics.shaders.GrayscaleShader;
import com.stencyl.graphics.shaders.SepiaShader;
import com.stencyl.graphics.shaders.InvertShader;
import com.stencyl.graphics.shaders.GrainShader;
import com.stencyl.graphics.shaders.ExternalShader;
import com.stencyl.graphics.shaders.InlineShader;
import com.stencyl.graphics.shaders.BlurShader;
import com.stencyl.graphics.shaders.SharpenShader;
import com.stencyl.graphics.shaders.ScanlineShader;
import com.stencyl.graphics.shaders.CSBShader;
import com.stencyl.graphics.shaders.HueShader;
import com.stencyl.graphics.shaders.TintShader;
import com.stencyl.graphics.shaders.BloomShader;



class Design_4_4_code02 extends ActorScript
{
   
   
   public function new(dummy:Int, actor:Actor, dummy2:Engine)
   {
      super(actor);
      nameMap.set("Actor", "actor");
      
   }
   
   override public function init()
   {
      
      /* =========================== On Actor =========================== */
      addMouseOverActorListener(__, function(mouseState:Int, list:Array<Dynamic>):Void
      {
         if(wrapper.enabled && 3 == mouseState)
         {
            playSoundOnChannel(getSound(6), Std.int(2));
         }
      });
      
   }
   
   override public function forwardMessage(msg:String)
   {
      
   }
}

squeeb

  • Posts: 1617
Isn't there a ghosting problem?  Maybe it's the same issue.. I'm running into something similar right now with trying to run and jump at the same time
http://community.stencyl.com/index.php/topic,50881.msg285849.html#msg285849

madScreenz

  • Posts: 9
Thanks for replying, I don't think this is the same issue. I'm testing on the computer with mouse clicks, not hand gestures (except for trying multiple notes). Clicking on the keys is precise but there is some sort of click lag - the first click has no sound and after that clicks give the notes of the previous key.

LIBERADO

  • *
  • Posts: 2720
I have downloaded and tested your file in Flash format, and it works fine for me.
No lag, the first click has sound, and the subsequent clicks give the correct sound.
   
You could clean the project (Run > Clean Project) and run the game again.
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

madScreenz

  • Posts: 9
Thank you, cleaning the project may have helped. But I noticed that when I try to touch keys simultaneously (I'm using a Surface) the click/sound lag problem happens. I wasn't sure how to implement multi-touch, it is enabled in the settings.
How would I use the code:
when touch is started/ ID of touch (not sure how this part works for me)?

LIBERADO

  • *
  • Posts: 2720
In your game you don't need to use the ID of touch.
   
You just have to use this code:
   
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

madScreenz

  • Posts: 9
Wow, that is interesting code! I plugged it in and it didn't work. You've been great though, you have no idea how much I appreciate your help. Any idea what I am doing wrong though?

LIBERADO

  • *
  • Posts: 2720
I have downloaded and tested it in an Android device, and my code perfectly works.
Take into account that the  Multi-Touch feature requires a touch screen with multi-touch capabilities.

« Last Edit: July 19, 2017, 06:57:05 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

madScreenz

  • Posts: 9
Interesting, I'll do the same - maybe it just doesn't work on my surface. Thanks again, I'll keep you posted  :)