SFML community forums
Help => Graphics => Topic started by: servvs 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
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
-
Ok another new problem im having is that when the enemy reaches the edge of the screen, it should change its direction by -1...
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?
-
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
-
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
-
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