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.


Messages - briant

Pages: [1]
1
General / Re: Projectile/Bullet help
« on: December 19, 2015, 04:35:46 am »
the most optimal method for coding this is.
2D shooter, bullets are always firing, are not needed once off the screen.
You might want to have a look at std::array so you can use that instead of that normal array  ;)
A fixed-sized array, as you have used - also with std::array, can fall apart when you need "just one more" bullet. What happens when you need 21 bullets? Does one of the earlier bullets get killed even if it's still travelling and visible?
A dynamically-sized array are of use when storing dynamic objects such as bullets. The first port of call for this type of storage is usually an std::vector. This could do your job fine but there are other storage containers that may work better, such as std::list (if the bullets could expire at unordered times or std::queue (if the bullets expire in order).

 [code=cpp][ */code]
(and omit the asterisk)
[code=cpp][/code]

(you can use the [nobbc][/nobbc] tags to display special characters in posts - but not inside code tags)

Neato thanks. I thought about using a dynamic array, but the way it's set up would never allow for that many to spawn, so I'll probably keep it static for simplicity's sake until later.

Also, I believe with how it's set up now it would just not spawn a bullet, so effectively your fire rate would just be slowed by a fixed amount.

2
General / Re: Projectile/Bullet help
« on: December 19, 2015, 03:40:29 am »
whoops.

3
General / Projectile/Bullet help
« on: December 19, 2015, 02:54:12 am »
Was just a dumb mistake, but I'm still curious what you think the most optimal method for coding this is.

2D shooter, bullets are always firing, are not needed once off the screen.

Hey, so I'm making a 2D shooter and everything's been good until I got to projectiles.

What I tried was making sf::Sprite array (i.e. sf::Sprite bullet[20]) and then recycling through them (once it goes off screen, stop rendering it).

It was fine until this line:

bullet[value].move[0,1];

Error   C3867   'sf::Transformable::move': non-standard syntax; use '&' to create a pointer to member   

Error   C2109   subscript requires array or pointer type   


Now, I can work around this by simply incrementing and setting its position, but it just seems strange that sf::Sprite.move won't work in this case.

Also, I highly doubt this is the optimal way to handle this. How would you go about coding bullets?

Thanks

Pages: [1]