Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualDynamite Andy

Posted 05 April 2013 - 08:40 AM

Hey,
So i'm working with a game engine that was wrote by charles kelly for his book programming 2D games.

His engine is rather good, however positioning images is rather bad as it does it as x = left corner and y = top of image
I don't want to do the maths to center an image in the position x,y i'd much rather write a function for it..

there's already functions for getting the center x and center y.

 

however how would i go about writing a function so that it takes int x, int y and moves the image so that its center is x,y?

// Return center X.
    virtual float getCenterX()      {return spriteData.x + spriteData.width/2*getScale();}

    // Return center Y.
    virtual float getCenterY()      {return spriteData.y + spriteData.height/2*getScale();}

// getScale() incase needed
// Return scale factor.
    virtual float getScale()    {return spriteData.scale;}

14o6l9e.png

The image to above shows what im after..

red = current setting.

blue = what im after


#3Dynamite Andy

Posted 05 April 2013 - 08:39 AM

Hey,
So i'm working with a game engine that was wrote by charles kelly for his book programming 2D games.

His engine is rather good, however positioning images is rather bad as it does it as x = left corner and y = top of image
I don't want to do the maths to center an image in the position x,y i'd much rather write a function for it..

there's already functions for getting the center x and center y.

 

// Return center X.
    virtual float getCenterX()      {return spriteData.x + spriteData.width/2*getScale();}

    // Return center Y.
    virtual float getCenterY()      {return spriteData.y + spriteData.height/2*getScale();}

// getScale() incase needed
// Return scale factor.
    virtual float getScale()    {return spriteData.scale;}

14o6l9e.pngThe image to the left describes what im after better than the way i am probably describing it.

red = current setting.

blue = what im after

 

 

however how would i go about writing a function so that it takes int x, int y and moves the image so that its center is x,y?


#2Dynamite Andy

Posted 05 April 2013 - 08:37 AM

Hey,
So i'm working with a game engine that was wrote by charles kelly for his book programming 2D games.

His engine is rather good, however positioning images is rather bad as it does it as x = left corner and y = top of image
I don't want to do the maths to center an image in the position x,y i'd much rather write a function for it..

there's already functions for getting the center x and center y.

 

// Return center X.
    virtual float getCenterX()      {return spriteData.x + spriteData.width/2*getScale();}

    // Return center Y.
    virtual float getCenterY()      {return spriteData.y + spriteData.height/2*getScale();}

// getScale() incase needed
// Return scale factor.
    virtual float getScale()    {return spriteData.scale;}

 

14o6l9e.png

however how would i go about writing a function so that it takes int x, int y and moves the image so that its center is x,y?


#1Dynamite Andy

Posted 05 April 2013 - 08:27 AM

Hey,
So i'm working with a game engine that was wrote by charles kelly for his book programming 2D games.

His engine is rather good, however positioning images is rather bad as it does it as x = left corner and y = top of image
I don't want to do the maths to center an image in the position x,y i'd much rather write a function for it..

there's already functions for getting the center x and center y.

 

// Return center X.
    virtual float getCenterX()      {return spriteData.x + spriteData.width/2*getScale();}

    // Return center Y.
    virtual float getCenterY()      {return spriteData.y + spriteData.height/2*getScale();}

// getScale() incase needed
// Return scale factor.
    virtual float getScale()    {return spriteData.scale;}


however how would i go about writing a function so that it takes int x, int y and moves the image so that its center is x,y?


PARTNERS