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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - stavsen

Pages: [1]
1
General / How would you go about translating a transformable ?
« on: March 08, 2018, 10:43:07 pm »
Hi
I have a Node object that inherits from sf::Transformable
and im able to move, rotate and scale it perfectly.

I was just wondering if it was also possible to translate its position by a given length?

the documentation doesn't seem to show any 'translate()' function ?
Im not very strong with vector math so im sorry if this is very simple

Thanks :)

2
General / Collision detection of a transformed entity
« on: March 01, 2018, 04:39:02 pm »
Hi,
I've been reading the code from the SFML Game Development book
and i have a small question regarding collision detection with the Node system.

If i have an Entity that inherits from SpriteNode, and the Entity has been transformed in some way
does sfml have any built in functions to check whether something is colliding with the sprite of the Entity?

(Usually i would just get the sprits bounds and then use the Rect class functions to check for collisions, but i obviously cant do that with the system showed in the book, as the sprites own transform isn't related to where its being drawn on the screen anymore :\ )

Or would i need something like a physics library for this?

Thanks :)


3
General / [SOLVED] Rotating child transform
« on: February 13, 2018, 10:34:34 pm »
Hi
I'm trying to make two sprites have a parent / child transform "relationship" like in unity

I have the following code:

Code: [Select]
int main(int argc, char** argv)
{
   RenderWindow wind(VideoMode(800,400),"test");
   Event event;

   Sprite sprite;
   Texture text;

   text.loadFromFile("C:\\test.jpg");
   sprite.setTexture(text);

   Transform trans;
   trans.translate(100,100);

   Transform parentTrans;
   parentTrans.translate(100,100);


   while(wind.isOpen())
   {

      while(wind.pollEvent(event) )
      {
         if(event.type == Event::Closed)
            wind.close();
      }

      wind.clear();

      parentTrans.translate(0.01f,0.0f);
      //trans.rotate(1.0f);

      wind.draw(sprite,parentTrans);
      wind.draw(sprite,trans*parentTrans);


      wind.display();

   }
   

   return 0;
}

When i run it i see 2 sprites.
One being drawn at 100, 100
and another one being drawn 100, 100 offset from its parent transform, just as expected.

And as i translate the parentTrans in the x direction
they are both affected, just as i want.

The problem is when i try to rotate the "child" sprites transform (trans).

When i uncomment the line where it rotates the sprite,
the child sprite does not rotate around itself (as it moves along in the x direction), as i was expecting.

Instead it rotates around the corner of the screen (0,0) in a circle that gets bigger and bigger as i keep translating the parent transform.

I'm guessing this is because i have to set the sprites origin to its position, right ?

but how can i do that? when the sprites own position actually never changes, and i cant do something like: 
Code: [Select]
trans.getPosition()
Is there some way i can get the a sprites position on the screen?
or is there a better solution to this problem?


Thanks in advance :)

4
General / how does translate work?
« on: February 08, 2018, 09:56:46 pm »
Hi
I've got a sprite which im drawing to the screen with a transform

what im consfused about it that my windows width is 600 px
and i called the transforms translate function, parsing (300, 0)
so i expected my sprite to be drawn in the middle of the screen (+the width of the sprite)
but it goes way off the screen?

And when i parse, say, (200,0) it moves almost to the end of the window ? even though its width is 600 ?

whats going on ?

doesn't translate "move" the transform by the pixels parsed in ?
i looked in the documentation, but it only says that the values parsed to translate are the offsets? but it it in pixels? or is it relative to the screen size?

Pages: [1]
anything