Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sprite Origin  (Read 4399 times)

0 Members and 1 Guest are viewing this topic.

aanthonyz

  • Newbie
  • *
  • Posts: 17
    • View Profile
Sprite Origin
« on: May 14, 2014, 06:39:44 am »
Hello, so for textures and and sprites, the origin is the top left, 0,0. If I want to change this to the bottoms left, should I just make it 0,(whatever the size of the image is), when I use the function setOrigin, or does that function do something completely different?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Sprite Origin
« Reply #1 on: May 14, 2014, 06:51:45 am »
Yes, set it to 0,(whatever the size of your sprite is) with setOrigin to set the origin of your sprite to its bottom left corner.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Sprite Origin
« Reply #2 on: May 16, 2014, 12:52:40 pm »
Yes, set it to 0,(whatever the size of your sprite is) with setOrigin to set the origin of your sprite to its bottom left corner.
Isn't he supposed to set it to the sprites height?
Sprite.setOrigin(0, Sprite.getTextureRect().height);

select_this

  • Full Member
  • ***
  • Posts: 130
  • Current mood: just ate a pinecone
    • View Profile
    • darrenferrie.com
Re: Sprite Origin
« Reply #3 on: May 16, 2014, 12:56:01 pm »
Yes, set it to 0,(whatever the size of your sprite is) with setOrigin to set the origin of your sprite to its bottom left corner.
Isn't he supposed to set it to the sprites height?
Sprite.setOrigin(0, Sprite.getTextureRect().height);

I'm sure that's what he meant by 'size'  :)
Follow me on Twitter, why don'tcha? @select_this

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Sprite Origin
« Reply #4 on: May 16, 2014, 12:58:44 pm »
Yes, set it to 0,(whatever the size of your sprite is) with setOrigin to set the origin of your sprite to its bottom left corner.
Isn't he supposed to set it to the sprites height?
Sprite.setOrigin(0, Sprite.getTextureRect().height);

I'm sure that's what he meant by 'size'  :)
Sorry i missunderstood then. I didn't think that paranthesis "(whatever the size of your sprite is)" was supposed to be the y and the 0 the x. I thought he meant to set it all to 0 no matter the size of the sprite ^^. nevermind :)

Doodlemeat

  • Guest
Re: Sprite Origin
« Reply #5 on: May 16, 2014, 07:05:28 pm »
use getGlobalBounds().height/width, then you will get the sprite dimensions. If you do getTextureRect(), you will get the texture dimensions.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Sprite Origin
« Reply #6 on: May 16, 2014, 07:12:26 pm »
No. getTextureRect is correct. It gives the dimensions of the textureRect without any transformation.
getGlobalBounds give the dimensions of the bounding box of the sprite with transformations applied (scale rotations etc.).
setOrigin ignores all transformations.

(And yes, that's what I meant by "size", I used the same formulation as he did :p )