Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


How should I do this [C++/SFML]


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 ZwodahS   Members   -  Reputation: 483

Like
0Likes
Like

Posted 23 February 2014 - 02:39 AM

I have a ObjectType class and a ObjectInstance class. ObjectInstance is just an instance of the ObjectType.

 

I want to be able to draw ObjectInstance based on the ObjectType class, something like the following

void ObjectInstance::draw()
{
    type.draw(*this);
}

where type is the ObjectType that is stored inside ObjectInstance.

 

The simplest way is to store a sprite in ObjectType and set the position when I am drawing.

The other method that I know of is to make use of sf::VertexArray + sf::Transform().translate to draw.

 

I am wondering if there is any other way to do so.

 

I know I can just store sprite in the ObjectInstances, but just say that if I need to do this, how should I do it? 

 

 

 

 

 


Check out my blog at zwodahs.github.io and zwodahs.itch.io/


Sponsor:

#2 ProtectedMode   Members   -  Reputation: 1335

Like
1Likes
Like

Posted 24 February 2014 - 01:49 AM

Maybe you should take a look at these sources and maybe even buy the book: SFML Game Development. As you can see in the sources, they let every scenenode (or object or whatever) inherit from sf::drawable and sf::transform. After that, they override the draw method in all entities to draw a sprite. This sprite is just stored inside the entity.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS