add sounds
This commit is contained in:
parent
fe73d7bec9
commit
26b6632158
35
jni/Sounds.cpp
Executable file
35
jni/Sounds.cpp
Executable file
@ -0,0 +1,35 @@
|
||||
#include "Sounds.h"
|
||||
#include <jni.h>
|
||||
|
||||
static JNIEnv* env = NULL;
|
||||
static jclass jSounds = NULL;
|
||||
|
||||
/** BackgroundSound */
|
||||
|
||||
void playBackgroundSound() {
|
||||
jmethodID method = env->GetStaticMethodID(jSounds, "JniPlayBackgroundSound", "()V");
|
||||
env->CallStaticVoidMethod(jSounds, method);
|
||||
}
|
||||
|
||||
void stopBackgroundSound () {
|
||||
jmethodID method = env->GetStaticMethodID(jSounds, "JniStopBackgroundSound", "()V");
|
||||
env->CallStaticVoidMethod(jSounds, method);
|
||||
}
|
||||
|
||||
/** GameSound - Gunshot */
|
||||
|
||||
void playGameSoundGunshot() {
|
||||
jmethodID method = env->GetStaticMethodID(jSounds, "JniPlayGunshotSound", "()V");
|
||||
env->CallStaticVoidMethod(jSounds, method);
|
||||
}
|
||||
|
||||
void stopGameSoundGunshot() {
|
||||
jmethodID method = env->GetStaticMethodID(jSounds, "JniStopGunshotSound", "()V");
|
||||
env->CallStaticVoidMethod(jSounds, method);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_fishrungames_crystalofrhylil_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis) {
|
||||
env = pEnv;
|
||||
jSounds = env->FindClass("com/fishrungames/crystalofrhyli/sounds/JniSoundCalls");
|
||||
playBackgroundSound();
|
||||
}
|
7
jni/Sounds.h
Executable file
7
jni/Sounds.h
Executable file
@ -0,0 +1,7 @@
|
||||
#include <jni.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_fishrungames_crystalofrhylil_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis);
|
||||
|
||||
}
|
@ -74,27 +74,27 @@ void TMyApplication::InnerInit()
|
||||
*SE::Console << "APP INIT\n";
|
||||
}
|
||||
|
||||
SE::ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex.txt", "shader1fragment.txt");
|
||||
SE::ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt");
|
||||
SE::ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt");
|
||||
SE::Renderer->PushShader("DefaultShader");
|
||||
|
||||
const std::string CONST_LOADING_BACKGROUND_BLACK = "loading_background_black";
|
||||
const std::string CONST_LOADING_TEXTURE = "loading";
|
||||
const std::string CONST_LOGO_SMALL_TEXTURE = "logo_small";
|
||||
|
||||
SE::ResourceManager->TexList.AddTexture(CONST_LOADING_BACKGROUND_BLACK + ".png", CONST_LOADING_BACKGROUND_BLACK);
|
||||
SE::ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE);
|
||||
SE::ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE);
|
||||
|
||||
SE::ResourceManager->TexList.AddTexture("console_bkg.bmp");
|
||||
|
||||
SE::ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
|
||||
|
||||
Inited = true;
|
||||
|
||||
SE::Renderer->SetOrthoProjection();
|
||||
|
||||
SE::ResourceManager->ShaderManager.AddShader("DefaultShader", "shader_vertex.txt", "shader_fragment.txt");
|
||||
SE::ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt");
|
||||
SE::ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt");
|
||||
SE::Renderer->PushShader("DefaultShader");
|
||||
|
||||
const std::string CONST_LOADING_BACKGROUND_BLACK = "loading_background_black";
|
||||
const std::string CONST_LOADING_TEXTURE = "loading";
|
||||
const std::string CONST_LOGO_SMALL_TEXTURE = "logo_small";
|
||||
|
||||
SE::ResourceManager->TexList.AddTexture(CONST_LOADING_BACKGROUND_BLACK + ".png", CONST_LOADING_BACKGROUND_BLACK);
|
||||
SE::ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE);
|
||||
SE::ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE);
|
||||
|
||||
SE::ResourceManager->TexList.AddTexture("console_bkg.bmp");
|
||||
|
||||
SE::ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
|
||||
|
||||
Inited = true;
|
||||
|
||||
SE::Renderer->SetOrthoProjection();
|
||||
|
||||
SE::Renderer->SetFullScreenViewport();
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -60,6 +60,8 @@ add_library( # Sets the name of the library.
|
||||
${JNI_PATH}/main_code.cpp
|
||||
${JNI_PATH}/match3/match3field.cpp
|
||||
${JNI_PATH}/android_api.cpp
|
||||
${JNI_PATH}/Sounds.cpp
|
||||
|
||||
)
|
||||
|
||||
add_library( engine
|
||||
|
@ -5,6 +5,8 @@ import java.util.Calendar;
|
||||
import android.content.Context;
|
||||
import android.opengl.GLSurfaceView;
|
||||
|
||||
import com.fishrungames.crystalofrhylil.sounds.JniSoundCalls;
|
||||
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
@ -58,6 +60,7 @@ class GLView extends GLViewAncestor
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height)
|
||||
{
|
||||
JniWrapper.Init(width,height);
|
||||
JniSoundCalls.init();
|
||||
}
|
||||
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config)
|
||||
|
@ -21,6 +21,8 @@ import android.view.MotionEvent;
|
||||
public class MainActivity extends Activity
|
||||
{
|
||||
|
||||
private static MainActivity instance;
|
||||
|
||||
GLView mView;
|
||||
|
||||
@Override
|
||||
@ -29,6 +31,8 @@ public class MainActivity extends Activity
|
||||
|
||||
super.onCreate(icicle);
|
||||
|
||||
instance = this;
|
||||
|
||||
EngineWrapper.LoadSalmonEngineLibrary();
|
||||
EngineWrapper.SetActivityInstance(this);
|
||||
EngineWrapper.SetupEnviroment();
|
||||
@ -88,6 +92,14 @@ public class MainActivity extends Activity
|
||||
EngineWrapper.ProcessKeyDown(keyCode, event);
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
public static MainActivity getInstance() {
|
||||
if (instance == null) {
|
||||
throw new RuntimeException("error GL2JNIActivity getInstance() - you are trying to get activity instance when it is not created or already destroyed");
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//package com.fishrungames.crystalofrhylil;
|
||||
|
@ -0,0 +1,43 @@
|
||||
package com.fishrungames.crystalofrhylil.sounds;
|
||||
|
||||
import android.media.MediaPlayer;
|
||||
|
||||
import com.fishrungames.crystalofrhylil.MainActivity;
|
||||
import com.fishrungames.crystalofrhylil.R;
|
||||
|
||||
public class JniSoundCalls {
|
||||
|
||||
native public static void initJniSounds();
|
||||
|
||||
private static MediaPlayer backgroundPlayer = null;
|
||||
private static MediaPlayer gunshotPlayer = null;
|
||||
|
||||
public static void init() {
|
||||
initJniSounds();
|
||||
}
|
||||
|
||||
public static void JniPlayBackgroundSound() {
|
||||
backgroundPlayer = MediaPlayer.create(MainActivity.getInstance(), R.raw.background_sound);
|
||||
backgroundPlayer.setLooping(true);
|
||||
backgroundPlayer.start();
|
||||
}
|
||||
|
||||
public static void JniStopBackgroundSound() {
|
||||
if (backgroundPlayer != null) {
|
||||
backgroundPlayer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public static void JniPlayGunshotSound() {
|
||||
gunshotPlayer = MediaPlayer.create(MainActivity.getInstance(), R.raw.gunshot_sound);
|
||||
gunshotPlayer.setLooping(false);
|
||||
gunshotPlayer.start();
|
||||
}
|
||||
|
||||
public static void JniStopGunshotSound() {
|
||||
if (gunshotPlayer != null) {
|
||||
gunshotPlayer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
BIN
proj.android-studio/app/src/main/res/raw/background_sound.mp3
Executable file
BIN
proj.android-studio/app/src/main/res/raw/background_sound.mp3
Executable file
Binary file not shown.
BIN
proj.android-studio/app/src/main/res/raw/gunshot_sound.mp3
Executable file
BIN
proj.android-studio/app/src/main/res/raw/gunshot_sound.mp3
Executable file
Binary file not shown.
BIN
src/.DS_Store
vendored
Normal file
BIN
src/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
src/fishrungames/.DS_Store
vendored
Normal file
BIN
src/fishrungames/.DS_Store
vendored
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user