Jump to content

  • Log In with Google      Sign In   
  • Create Account


Anubiss

Member Since 10 Jan 2012
Offline Last Active Mar 28 2012 12:59 AM

Topics I've Started

Animation - shakingProblem

27 March 2012 - 02:59 AM

hey guys.
following problem:

I want to let my startbutton shake if it is not touched within 10 seconds. this lecture is out of a book i baught for starting with Android programing. But although i am thinking of havin done everything correct, the button does not shake.

buttonID = button1

res/anim/wackeln.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
		  android:fromDegrees="-40"
		  android:toDegrees="40"
		  android:duration="1000"
		  android:repeatCount="20" />


and in my main activity:

private Animation animationWackeln;
private Button startButton;
private Handler handler = new Handler();


public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Button button = (Button) findViewById(R.id.button1);
		button.setOnClickListener(this);
		animationWackeln = AnimationUtils.loadAnimation(this, R.anim.wackeln);
		startButton = (Button)findViewById(R.id.button1);  
	}


private class WackleButton implements Runnable {

public void run() {
startButton.startAnimation(animationWackeln);
}
}

@Override

protected void onResume(){
super.onResume();
handler.postDelayed(new WackleButton(), 1000*10);
}

i hope someone will help. thank you

Creating A New Object Ingame

10 January 2012 - 12:08 PM

Hey friends.
I hope you can help me with my lil game what i´m writing in C with the PaLib library for my nintendo ds. I have a ship what´s flying through the orbit. when the ship is landing in the space-station i want to have the option "buy new station". But how do i code the creation of a new station. i just need the idea of how doing that.
Will be happy about any help.


Here´s the code till now:

// Includes
#include <PA9.h>
#include "gfx/all_gfx.c"
#include "gfx/all_gfx.h"
int main(int argc, char ** argv)
{
PA_Init();  
PA_InitVBL();
PA_EasyBgLoad(0, 1, aa);
PA_InitText(1,0);
PA_LoadSpritePal(0, 0, (void*)vaisseau_Pal);
PA_LoadSpritePal(0, 1, (void*)station01_Pal);
PA_CreateSprite(0, 0,(void*)vaisseau_Sprite, OBJ_SIZE_32X32,1, 0, 128-16, 96-16); // Das SChiff auf Mitte des unteren Screens setzen
PA_SetSpriteRotEnable(0,0,0);
u16 angle = 0;
int x = (128) << 8;
int y = (96) << 8;
int sx;
int sy;
typedef struct{
int x;
int xmax;
int schalter;
}pflanze;
pflanze buche;
buche.xmax=1000;
buche.schalter=0;
int scrollx = 0;
int scrolly = 0;

//Raumstation:
/////////////////////////////////////////////////
typedef struct{
int x;
int y;
int flag;
int entfx;
int entfy;
}station;
station rs;
//station fremd[10];//0-9
rs.x=200;
rs.y=96;
rs.flag=0;
rs.entfx;
rs.entfy;
void station01test(void){
rs.entfx=(sx>>8)-(rs.x);//Entfernung zwischen Station und Raumschiff messen
  if (rs.entfx<0){rs.entfx=-rs.entfx;}//Betrag, falls Entfernung negativ!
rs.entfy=(sy>>8)-(rs.y);
  if (rs.entfy<0){rs.entfy=-rs.entfy;}


if (rs.flag==0){
  PA_CreateSprite(0, 2,(void*)station01_Sprite, OBJ_SIZE_64X64,1, 1, rs.x-16, rs.y-16);
  rs.flag=1;
}

if ((rs.entfx>100)&&rs.flag==1){
  PA_DeleteSprite (0, 2);
  rs.flag=0;
}

if ((rs.entfy>100)&&rs.flag==1){
  PA_DeleteSprite (0, 2);
  rs.flag=0;
}

if ((rs.entfx<30)&&(rs.entfy<30)){
  PA_OutputText(1,0,2,"'START' zum Landen-");
}
if ((rs.entfx>30)||(rs.entfy>30)){
  PA_OutputText(1,0,2,"					  ");
}

}
//Einfacher test:
/////////////////////////////////////////////////
void wachse(void){
if (buche.schalter==1)
  if(buche.x<buche.xmax)
  buche.x++;
  if(buche.x==buche.xmax)
  buche.x=buche.xmax;

}

//STATUSBILDSCHIRM
//////////////////////////////////////////////////////////////////
void statusscreen(void){
  //Ausgabe von Informationen auf oberen Screen:
  ////////////////////////////////////////////////////////////////////////////////
  PA_OutputText(1,0,12,"Map-x: %02d", scrollx>>8);
  PA_OutputText(1,0,13,"Map-y: %02d", scrolly>>8);
  PA_OutputText(1,0,14,"-------------------");
  PA_OutputText(1,0,15,"Schiff-x: %02d", sx>>8);
  PA_OutputText(1,0,16,"Schiff-y: %02d", sy>>8);
  PA_OutputText(1,0,17,"-------------------");
  PA_OutputText(1,0,18,"x von Station entfernt: %02d", rs.entfx);
  PA_OutputText(1,0,19,"y von Station entfernt: %02d", rs.entfy);
  PA_OutputText(1,0,20,"Winkel des Schiffes: %02d", angle);
}

//MAIN:
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
while (1)
{
  //Test-Buche: zählt von 0 bis 1000, wenn "A" gedrückt wird
  if (Pad.Newpress.A) buche.schalter=1;
  wachse();
  PA_OutputText(1,0,0,"%02d", buche.x);


  //Winkelberechnung-Flugschiff:
  ///////////////////////////////////////////////////////////////////////////////
  angle = PA_GetAngle(x>>8, y>>8, Stylus.X, Stylus.Y);					   //
  PA_SetRotsetNoZoom(0, 0, angle); // Änderung des Schiffswinkels	   //
  //Flugschiff-Koordinaten AUSSERHALB DER ENGINE:
  sx=(scrollx+x);
  sy=(scrolly+y);

  //Hintergrund-Scrolling:
  //////////////////////////////////////////////////////////////////////////////
  if(Pad.Held.B){				//
   scrollx += PA_Cos(angle);			//
   scrolly += PA_Sin(angle);
  };
  //Map-Grenzen:				//
  if((scrollx>>8)>(2560-255)){
   scrollx=590080;
  };
  if((scrollx>>8)<0){
   scrollx=0;
  };
  if((-scrolly>>8)>(1600-191)){
   scrolly=-360704;
  };
  if((-scrolly>>8)<0){
   scrolly=0;
  };
  //Set-Map:
  PA_LargeScrollXY(0, 1, scrollx>>8, -scrolly>>8);

  statusscreen();

  PA_SetSpriteXY(0, 0, (x>>8)-16, (y>>8)-16);
  PA_SetSpriteXY(0, 2, ((rs.x-16)+(-scrollx>>8))-16, ((rs.y-16)+(scrolly>>8))-16);
  station01test();
  PA_WaitForVBL();
}

return 0;

}

PARTNERS