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

Author Topic: sprite.GetPosition and Vector2f  (Read 2900 times)

0 Members and 1 Guest are viewing this topic.

servvs

  • Newbie
  • *
  • Posts: 10
    • View Profile
sprite.GetPosition and Vector2f
« on: April 11, 2010, 07:10:35 am »
So basically I am trying to make a ball that bounces around, but im unsure how to use the geposition and vector2 functions to do that. I don't understand how to use getposition to assign a float to said variable and then have my if statement read said variable and change directions when said variable reaches a point of the screen that it should not go out of.... A little enlightenment please?

while im here. I also want to learn more about classes. I understand them to a point and I know it makes it easier to create multiple enemies with their health and weather they are alive stored in the class, but i can't figure out how to implement that either... Basically I want a class for enemies with those things in them that way I can create my for loop and have multiple instances of the enemies but I can't get it to work with the sprites and what not... An example would be great though, or just some more enlightenment

[edit]
I typed originally getscale :p same concept though

[edit]
My latest attempt is
Code: [Select]

        sf::Vector2f::x EnemyWidthCheck;
        float enemyWidthCheck = EnemyWidthCheck.GetPosition;
        if (enemyWidthCheck >= wWidth)
        {
            enemyMove = enemyMove * -1;
        }


[edit]
Ugh I feel dumb... its just sprite.GetPosition().x;

Still, any resources on classes would be great :p

servvs

  • Newbie
  • *
  • Posts: 10
    • View Profile
sprite.GetPosition and Vector2f
« Reply #1 on: April 11, 2010, 08:22:59 am »
Ok another new problem im having is that when the enemy reaches the edge of the screen, it should change its direction by -1...

Code: [Select]

float enemyMove = 150;
float enemyX = Sprite2.GetPosition().x;
bool bEnemy = true;
if (enemyX >= wWidth)
bEnemy = false;
if (bEnemy)
{
       Sprite2.Move(enemyMove * ElapsedTime, 0);
}
else if(!bEnemy)
{
       Sprite2.Move(enemyMove * ElapsedTime * -1, 0);
}


I know this code is defunct, and that it creates an endless loop and gets stuck between the edge of the window and one pixel from the edge of the window causing it to bounce by 1 pixel over and over again. I have tried numerous things but cant get this to work, any ideas?

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
sprite.GetPosition and Vector2f
« Reply #2 on: April 11, 2010, 08:27:49 am »
I'm just starting on this myself.

It should go like this:

-load resources into memory

-instantiate classes that use these sources (make sure they have an id string)

-place in an array

-modify/update through array

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
sprite.GetPosition and Vector2f
« Reply #3 on: April 11, 2010, 08:29:07 am »
Quote from: "Ashenwraith"
I'm just starting on this myself.

It should go like this:

-load resources into memory

-instantiate classes that use these resources (make sure they have an id string)

-place in an array

-modify/update through array

servvs

  • Newbie
  • *
  • Posts: 10
    • View Profile
sprite.GetPosition and Vector2f
« Reply #4 on: April 11, 2010, 08:34:52 am »
Quote from: "Ashenwraith"
I'm just starting on this myself.

It should go like this:

-load resources into memory

-instantiate classes that use these sources (make sure they have an id string)

-place in an array

-modify/update through array


Im still getting used to c++ could you show me an example for that? and this helps a lot :D

 

anything