Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » General (non-technical) » Polish users » ADT-Problem(Problem)
icon1.gif  ADT-Problem [message #1092284] Thu, 22 August 2013 15:13
Amadeusz Czader is currently offline Amadeusz Czader
Messages: 1
Registered: August 2013
Junior Member
Witam!
Proszę o pomoc.Tworzę swoją pierwszą grę a androida przy pomocy eclipse'a.Pomimo tego iż w kodzie jest wszystko zrobione poprawnie nie nie ma komunikatów o błędach po kompilacji i użyciu przycisku 'start" jest napisane, że aplikacja przestała działać po wielu próbach nie udało mi się tego zmienić więc mam nadzieję ,że ktoś wskaże mi mój błąd/błędy

Fragmenty kodu:
Menu główne:

public class Mainmenu extends Activity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menuscreen);

final Engine engine = new Engine();

/**Ustawia opcje przycisków*/

ImageButton start = (ImageButton) findViewById(R.id.startbtn);
ImageButton exit = (ImageButton) findViewById(R.id.exitbtn);


start.getBackground().setAlpha(Engine.GAME_BUTTON_ALPHA);
start.setHapticFeedbackEnabled(Engine.HAPTIC_BUTTON_FEEDACK);

exit.getBackground().setAlpha(Engine.GAME_BUTTON_ALPHA);
exit.setHapticFeedbackEnabled(Engine.HAPTIC_BUTTON_FEEDACK);



start.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent game = new Intent(getApplicationContext(), Game.class);
Mainmenu.this.startActivity(game);
}
});

exit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean clean = false;
clean = engine.onExit(v);
if (clean) {
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
}
}
});
}}

gra, widok grz, to i renderer

package com.androidgame;

import android.app.Activity;
import android.os.Bundle;

public class Game extends Activity {

private Gameview gameView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameView = new Gameview(this);
setContentView(gameView);

}

@Override
protected void onResume() {
super.onResume();
gameView.onResume();
}

@Override
protected void onPause() {
super.onPause();
gameView.onPause();
}

}

package com.androidgame;

import android.content.Context;
import android.opengl.GLSurfaceView;

public class Gameview extends GLSurfaceView {
private Gamerenderer renderer;

public Gameview(Context context) {
super(context);

renderer = new Gamerenderer();
this.setRenderer(renderer);
}

}

package com.androidgame;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLUtils;

public class Gamebackground {

private FloatBuffer vertexBuffer;
private FloatBuffer textureBuffer;
private ByteBuffer indexBuffer;

private int[] textures = new int[1];

private float vertices[] = {
0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,

};

private float texture[] = {
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,

};

private byte indices[] = {
0, 1, 2,
0, 2, 3,
};

public Gamebackground() {


ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4);
byteBuf.order(ByteOrder.nativeOrder());
vertexBuffer = byteBuf.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);

byteBuf = ByteBuffer.allocateDirect(texture.length * 4);
byteBuf.order(ByteOrder.nativeOrder());
textureBuffer = byteBuf.asFloatBuffer();
textureBuffer.put(texture);
textureBuffer.position(0);

indexBuffer = ByteBuffer.allocateDirect(indices.length);
indexBuffer.put(indices);
indexBuffer.position(0);
}


public void loadTexture(GL10 gl, int texture, Context context) {
InputStream imagestream = context.getResources().openRawResource(texture);
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream(imagestream);
} catch (Exception e) {
} finally {
//Zawsze czyść i zamykaj
}
try {
imagestream.close();
imagestream = null;
}catch (IOException e) {
}
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
GL10.GL_REPEAT);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}

public void draw(GL10 gl) {
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glFrontFace(GL10.GL_CCW);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glCullFace(GL10.GL_BACK);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDisable(GL10.GL_CULL_FACE);
}
}

package com.androidgame;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView.Renderer;

public class Gamerenderer implements Renderer {

private Gamebackground background = new Gamebackground();
private Gamebackground background2 = new Gamebackground();
private Character player1 = new Character();
private int characterBankFrames = 0;

private float bgScroll;
private float bgScroll2;

private void movePlayer1(GL10 gl) {
switch (Engine.playerMoveAction) {
case Engine.PLAYER_BANK_RELASE:
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glScalef(.25f, .25f, 1f);
gl.glTranslatef(Engine.playerBankPosX, 0f, 0f);
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, 0.0f);
player1.draw(gl);
gl.glPopMatrix();
gl.glLoadIdentity();
characterBankFrames += 1;


break;
case Engine.PLAYER_BANK_LEFT:
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glScalef(.25f, .25f, 1f);
if (characterBankFrames < Engine.PLAYER_FRAMES_BETWEEN_ANI && Engine.playerBankPosX > 0) {
Engine.playerBankPosX -= Engine.PLAYER_BANK_SPEED;
gl.glTranslatef(Engine.playerBankPosX, 0f, 0f);
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glLoadIdentity();
gl.glTranslatef(0.75f, 0.0f, 0.0f);
characterBankFrames += 1;
} else if (characterBankFrames >= Engine.PLAYER_FRAMES_BETWEEN_ANI
&& Engine.playerBankPosX > 0){
Engine.playerBankPosX -= Engine.PLAYER_BANK_SPEED;
gl.glTranslatef(Engine.playerBankPosX, 0f, 0f);


} else {
gl.glTranslatef(Engine.playerBankPosX, 0f, 0f);
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, 0.0f);

}
player1.draw(gl);
gl.glPopMatrix();
gl.glLoadIdentity();


break;
case Engine.PLAYER_BANK_RIGHT:
break;
case Engine.PLAYER_BANK_UP:
break;
case Engine.PLAYER_BANK_DOWN:
default:
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glScalef(.25f, .25f, 1f);
gl.glTranslatef(Engine.playerBankPosX, 0f, 0f);
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, 0.0f);
player1.draw(gl);
gl.glPopMatrix();
gl.glLoadIdentity();

break;
}

}
@Override
public void onDrawFrame(GL10 gl) {
try {
Thread.sleep(Engine.GAME_THREAD_FPS_SLEEP);
} catch (InterruptedException e) {
e.printStackTrace();
}

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

scrollBackground(gl);
scrollBackground2(gl);

//Pozostałe metody rysujące elementy gry będą wywoływane tutaj

gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
}

private void scrollBackground(GL10 gl) {
if (bgScroll == Float.MAX_VALUE) {
bgScroll = 0f;
}
/*Poniższy kod resetuje skalę i przesunięcia trybu macierzy modelu,
*nie przesuwa jej.
*/
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glScalef(1f, 1f, 1f);
gl.glTranslatef(0f, 0f, 0f);

gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, bgScroll, 0.0f); //przewiajnie tekstury

background.draw(gl);
gl.glPopMatrix();
bgScroll += Engine.SCROLL_BACKGROUND_1;
gl.glLoadIdentity();

}

private void scrollBackground2(GL10 gl) {
if (bgScroll2 == Float.MAX_VALUE) {
bgScroll2 = 0f;

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glScalef(.5f, 1f, 1f);
gl.glTranslatef(1.5f, 0f, 0f);

gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, bgScroll2, 0.0f);

background2.draw(gl);
gl.glPopMatrix();
bgScroll2 += Engine.SCROLL_BACKGROUND_2;
gl.glLoadIdentity();
}
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {

gl.glViewport(0, 0, width, height);

gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0f, 1f, 0f, 1f, -1f, 1f);
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);

gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);

background.loadTexture(gl, Engine.BACKGROUND_1,
Engine.context);
background2.loadTexture(gl, Engine.BACKGROUND_2,
Engine.context);
player1.loadTexture(gl, Engine.PLAYER_CHARACTER, Engine.context);
}
}







Previous Topic:Eclipse na OpenSuse 12.3
Next Topic:Problem z uruchomieniem Eclipse oraz uruchamianiem projektu
Goto Forum:
  


Current Time: Mon Sep 22 10:33:34 GMT 2014

Powered by FUDForum. Page generated in 0.01554 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software