[try Beta version]
Not logged in

 
my little game and still a bit new to classes and how to access one class from another

Mar 6, 2015 at 5:31am
alright I have a class for shooting(shots) in my game, also a player, map and game class.

so I have the player creating the shots with
1
2
3
4
5
void Player::shoot()
{
	//not sure how to get the new shot everytime 
 	shot.push_back(Shots(Player::getPosition(),sf::Color::Red, 2.5f, sf::Vector2f(-1.f, -1.f)));// sf::Color::Red, 2.5f, (-1.f, -1.f));
}


I have the main creates game and game creates map and map creates player. so where I draw the player I think I want to draw the shots as well and I have this.....
1
2
3
4
5
window.draw(circle) // this is the player for now
for(int i = 0; i < shot.size(); i++)
	{
		window.draw(shot[i].projectile); // but here it says projectile is inaccessable
	}


I have the shot as a circle as well as "sf::CircleShape projectile;"
im a little lost on how I can get this to draw to the screen.
Mar 6, 2015 at 5:36am
You should tell each shot to draw itself to the window, rather than stealing its job.
Mar 6, 2015 at 5:48am
ok, not sure how to go about this, I want to make a new function called render in the shots class but then im not quite sure how to draw up the individual shot this is what I have but does not work
[code]
void Shots::render(sf::RenderWindow& window)
{
for(int i = 0; i < shot.size(); i++)
window.draw(projectile[i]);
}
[code]
Mar 6, 2015 at 5:50am
A shot should only worry about itself. Why do you have a loop? There is nothing to loop over - just draw the one and only graphic for the shot.
Mar 6, 2015 at 5:57am
ok but what about all the other shots? do I not need to draw them as well
Mar 6, 2015 at 5:59am
In your player class, you can loop through the shots and tell them to draw themselves. That means, calling the function you made.
Mar 6, 2015 at 6:02am
thank u I did get it to start working, now the tough part of getting them to move and collide :)
Topic archived. No new replies allowed.