sprite location bug March 31, 2010 07:53AM | Registered: 15 years ago Posts: 444 |
arrow.SetPosition(initX,initY);where initX and initY is the location I want the center of the back of the arrow. When I run this, the size and direction work great, but the position is off. When the code is this
arrow.SetPosition(initX-arrowimg.GetWidth()/2,initY-arrowimg.GetHeight());It doesn't appear. here is my entire source that applies, the rest has to do with unrelated events.
int main(int argc, char **argv) { /**************** * VARIABLES :) * ****************/ Image arrowimg; Sprite arrow; bool bulletAlive = false; bool levelDone = false; bullet shootingBullet; int i; int initX = 50; int initY = 50; int startX; int startY; float spd=3; float ang=85*(M_PI/180); LayerManager manager(16); // Create the game window and initalise the VIDEO subsystem GameWindow *gwd = new GameWindow; gwd->InitVideo(); gwd->SetBackground((GXColor){ 0, 0, 0, 255 }); /******************** * Set up images * * to be placed * * on screen * ********************/ manager.Append(&ptrspr); manager.Append(&shootingBullet.bulletQuad); manager.Append(&planet1); manager.Append(&target); for(;;) { do { WPAD_ScanPads(); PAD_ScanPads(); WPAD_IR(0,&ir); arrowimg.LoadImage(arrow_png); arrow.SetImage(&arrowimg); arrow.SetRefPixelPosition(arrowimg.GetWidth()/2,arrowimg.GetHeight()); ptrspr.SetPosition(ir.x-8,ir.y); int buttonsDownCube = PAD_ButtonsDown(0); int buttonsDown = WPAD_ButtonsDown(0); int buttonsHeld = WPAD_ButtonsHeld(0); int buttonsUp = WPAD_ButtonsUp(0); if(buttonsDown&WPAD_BUTTON_HOME||buttonsDownCube & PAD_BUTTON_START) exit(0);//homemenu(gwd); /******************** * Create Arrow * * and send off * * bullet * *********************/ if(buttonsDown&WPAD_BUTTON_A){ if(bulletAlive==false){ startX = ir.x; startY = ir.y; //arrow.SetPosition(initX-arrowimg.GetWidth()/2,initY-arrowimg.GetHeight()); arrow.SetPosition(initX,initY+arrowimg.GetHeight()); Xx = initX; Yy = initY; manager.Append(&arrow); } } if(buttonsHeld&WPAD_BUTTON_A){ if(bulletAlive==false){ arrow.SetStretchWidth(calcDistance(startX,startY,ir.x,ir.y)/150); arrow.SetStretchHeight(arrow.GetStretchWidth()); if(startX!=ir.x){ ang = atan( (ir.y-startY)/ (startX-ir.x)); if((startY-ir.y>0&&ir.x-startX>0)||(startY-ir.y<0&&ir.x-startX<0)){ //flip on TL 45 ang = (.75*M_PI) + (.75*M_PI-ang); } if(startY-ir.y<0&&ir.x-startX>0){ //flip on TR 45 ang = (1.25*M_PI) + ((1.25*M_PI)-ang); } if(startY-ir.y>0&&ir.x-startX<0){ //flip on T 90 ang = (.5*M_PI) + ((.5*M_PI)-ang); //add .5 PI ang += .5*M_PI; } if(startY-ir.y>0&&ir.x-startX>0){ ang += M_PI; } ang += M_PI; } else if(ir.y > startY){ ang = 1.5*M_PI; } else { ang = .5* M_PI; } arrow.SetRotation((ang*(180/M_PI))/2); } } if(buttonsUp&WPAD_BUTTON_A){ if(bulletAlive==false){ spd = calcDistance(startX,startY,ir.x,ir.y)/15; if(startX!=ir.x){ ang = atan( (ir.y-startY)/ (startX-ir.x)); if(ir.x>startX) ang += M_PI; } else if(ir.y > startY){ ang = 1.5*M_PI; } else { ang = .5* M_PI; } shootingBullet.resetBullet(initX,initY,spd,ang,0,0); bulletAlive = true; manager.Remove(&arrow); } } /************************ * Math for Planets * * and also getting * * rid of dead * * bullets * ************************/ manager.Draw(0,0); gwd->Flush(); } while (levelDone == true); } return 0; }If you want my entire source then just ask, and if so should I post it between code blocks, or should I find a file hosting site. If so, what is a good one.
Re: sprite location bug April 01, 2010 04:57AM | Registered: 15 years ago Posts: 444 |
Re: sprite location bug April 01, 2010 06:27AM | Registered: 14 years ago Posts: 118 |
Re: sprite location bug April 01, 2010 04:12PM | Registered: 15 years ago Posts: 444 |