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

Author Topic: 2.0 ,At Which point should i set OriginPoint in Sprite Objects?;  (Read 2611 times)

0 Members and 1 Guest are viewing this topic.

Pepsi

  • Newbie
  • *
  • Posts: 4
    • View Profile
Greeting,


let's assume i have character that has 7 frames in walking mode, and 2 in crunch mode.

the frames in crunch mode is almost half size of walking mode rectangle.

now if i set  all the frames (walking+crunch) to its center (0.5 of W , 0.5 of H), i will face problem in Set position function => the character is not on the surface in crunch mode.

so what is the best point to set Character origin point?

Thanks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: 2.0 ,At Which point should i set OriginPoint in Sprite Objects?;
« Reply #1 on: October 05, 2012, 01:32:02 pm »
I don't quite follow you, but it seems to me that you're doing a rather uncommon thing for animation.

Usually if a character has different animation frames, it's a good practice to have all of those different moves in one image which then gets loaded as texture. If you now want to change the frame, you simply change the texture rect (setTextureRect) of the sprite and the new frame will appear.
If the animation is done that way, it doesn't matter what the origin is and you get slightly better performance since changing the texture rectangle is a relatively cheap operation. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Pepsi

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: 2.0 ,At Which point should i set OriginPoint in Sprite Objects?;
« Reply #2 on: October 05, 2012, 01:39:47 pm »
yeah that's what I did,
the problem appears in crunch mode (when user press down button) the character goes up the surface , crunch should be on the surface/ floor

Animating 2D character is what I'm doing as Following:
- have x.png conains all the frames
- use setTextureRect(size) to get appropriate frame
- set origin
- move / or dont move
- draw
« Last Edit: October 05, 2012, 01:41:22 pm by Pepsi »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: 2.0 ,At Which point should i set OriginPoint in Sprite Objects?;
« Reply #3 on: October 05, 2012, 01:48:45 pm »
I'm not sure, but when changing the texture rect, do just change it's position or also it's size?
You should keep the size of the rect always the same and only change the 'position' of the rectangle on the texture. With that you set the origin once and it always applies to your character.
Of course it will 'waste' a bit more image space, since you'll have empty places above the crouch frames, but that doesn't really hurt... ;)
As for collision detection and other physic stuff that would depend on the sprite rectangle, it's better to separate the graphic and logic part, thus you should use the texture rect as your input for the collision detection (or if so convert it to match the current state).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Pepsi

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: 2.0 ,At Which point should i set OriginPoint in Sprite Objects?;
« Reply #4 on: October 05, 2012, 02:11:41 pm »
eXpl0it3r , Thanks for fast replays :)

Quote
do just change it's position or also it's size?
i change both (x,y) and the (W, H) of the new REct

Quote
You should keep the size of the rect always the same
well my sprite have different dimension in some frames, that's why I'm having problem to where set the origin, since the move, setposition depend on the origin point of the sprite.

Is it good to have the origin point at (W,H)? it has side effect on scale function , but it will help in solving the problem of having the sprite off the floor ?
« Last Edit: October 05, 2012, 02:17:33 pm by Pepsi »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: 2.0 ,At Which point should i set OriginPoint in Sprite Objects?;
« Reply #5 on: October 05, 2012, 03:20:18 pm »
eXpl0it3r , Thanks for fast replays
Glad I can reply. ;)

well my sprite have different dimension in some frames, that's why I'm having problem to where set the origin, since the move, setposition depend on the origin point of the sprite.
That's what I suspected and that's why I said you should change the frames, so all have the same size. You'll safe yourself quite some trouble... ;)

Is it good to have the origin point at (W,H)?
Good or bad always depends on the problem you have infront of you. As I said I'd use a fixed size for all of my frames and could eliminate all the problems (scaling etc) with ease, but I guess setting the origin to (W, H) could also work, even though with some side effects.

It's your code, so you have to decide. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Pepsi

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: 2.0 ,At Which point should i set OriginPoint in Sprite Objects?;
« Reply #6 on: October 05, 2012, 09:57:32 pm »
Thanks for help/feedback. :)

 

anything