I'm developing a game as a learning-process, and since everything I do is new to me, I have alot of problems, usually I can fix it myself but right now I'm stuck and need help.
Link to a recording of my game: http://www.youtube.com/watch?v=nejaMtug09A&feature=youtube_gdata
As you can see in this video I have my joystick working and my animation 80% complete.
!!EDIT : SOLVED!! So first question: How do I get my animation to stop? I have a variable called "dragging" that is set to "true" whenever I move, so it shouldnt be that hard,
when dragging == false (stop animation and display the correct image of my sprite standing still, in the correct direction);
!!EDIT : NOT SOLVED!! My second question: As you can see in the video I get a bullet to spawn when I press the circle in the bottom right corner, I can get it to spawn on my sprite ( or at the end of my sprites gun) if I want, but what I cant do is setting a speed for my bullet, and also I want to be able to have multiple bullets on the screen at once, not just one, with some delay between bullets ofc.
If you can answer anyone of these questions you've made my life alot easier :) Posting code here:
the code for my sprite-animation:
private static final int BMP_ROWS = 4;
private static final int BMP_COLUMNS = 3;
private int currentFrame = 0;
public int getAnimationRow() {
direction = (int) Math.round(controls.getAngle()) % happy.getBmpRows();
return DIRECTION_TO_ANIMATION_MAP[direction];}
private void update() {
currentFrame = ++currentFrame % BMP_COLUMNS;
}
public void draw(Canvas canvas, int x, int y) {
update();
int srcX = currentFrame * width;
int srcY = panel.getAnimationRow() * height;
Rect src = new Rect(srcX, srcY, srcX + width, srcY + height);
Rect dst = new Rect(x, y, x + width, y + height);
canvas.drawBitmap(bitmap, src, dst, null);
}
the code for my controls:
if (event.getAction() == MotionEvent.ACTION_DOWN && (int) event.getX() > 0 && (int) event.getX() < 100
&& (int) event.getY() > 300 && (int) event.getY() < 400) {
dragging = true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
dragging = false;
shooting=false;
}
if (dragging) {
// get the pos
touchingPoint.x = (int) event.getX();
touchingPoint.y = (int) event.getY();
double angle = Math.atan2(touchingPoint.y - inity,
touchingPoint.x - initx) / (Math.PI / 180);
spriteAngle = Math.atan2(touchingPoint.y - inity,
touchingPoint.x - initx) / (Math.PI / 2) + 2;
pointerPosition.y += Math.sin(angle * (Math.PI / 180))
* (touchingPoint.y / 70);
pointerPosition.x += Math.cos(angle * (Math.PI / 180))
* (touchingPoint.y / 70);
if (event.getAction() == MotionEvent.ACTION_DOWN && (int) event.getX() > 650 && (int) event.getX() < 750
&& (int) event.getY() > 300 && (int) event.getY() < 400){
shooting = true;
}
Lastly, my render-method:
public void render(Canvas canvas) {
canvas.drawColor(Color.BLUE);
canvas.drawBitmap(joystick.get_joystickBg(), controls.initx - 50, controls.inity - 50, null);
happy.draw(canvas, controls.pointerPosition.x, controls.pointerPosition.y);
canvas.drawBitmap(joystick.get_joystick(), controls.touchingPoint.x - 26, controls.touchingPoint.y - 26, null);
canvas.drawBitmap(joystick.get_trigger(), controls.triggerX - 50, controls.triggerY - 50, null);
if(controls.getShooting() == true){
canvas.drawBitmap(bullet.getStartBullet(), 200, 200, null);
}
displayFps(canvas, avgFps);
If you've read all this then you are a very patient person, I posted alot of code but I think you will need it all to be able to help, if you need more let me know and Ill post ASAP :)
Thank you!
Will post the code of the fixed problem down here for any1 that might have the same issue in the future:
Code that fixed my animation-question:
public void render(Canvas canvas) {
canvas.drawColor(Color.BLUE);
canvas.drawBitmap(joystick.get_joystickBg(), controls.initx - 50, controls.inity - 50, null);
if(controls.getDragging() == true){
happy.update();
}else{
happy.setFrame(1);
}
happy.draw(canvas, controls.pointerPosition.x, controls.pointerPosition.y);