Actors with multiple Textures

Posted by (twitter: @aaronsnoswell)
January 23rd, 2013 11:46 pm

Hi all!

This is a shameless re-post of my Stack Exchange Game Development question of the same name.

In my 2D side-scroller game I have a bunch of actors being drawn, each of which has a single, non-animated Texture (a png image). These actors all inherit from a base GameActor class.

I want to add some more NPC’s (e.g. tanks or cannons) that have one texture that doesn’t move (the base) and another that rotates to shoot at things (the gun / barrel). How should I structure my Actor class hierarchy so as to allow for this? Should I refactor my base Actor class to allow for N textures? Or should I create a brand new sort of Actor for things that need > 1 texture (and then have to manage these actors separately from ‘regular’ actors)? Or is there a better approach I can’t see?

Thus far I’ve been opting to keep things as simple as possible (KISS, right?), but am not sure how to proceed.

Any pointers greatly appreciated.

3 Responses to “Actors with multiple Textures”

  1. GFM says:

    Why not make a ‘actors-group-with-position’?

    If you’ve already use flixel, I mean something like FlxGroup, but with position and every member is moved when you move the group.
    If not, how about this: extend the GameActor (so everything is accessed the same way) and give it an array of GameActor. Then, for the tank, for example, you would have an actor that is the non-animated part and other with the animated part, but would only need to rotate the animated part. =D
    For this to work, though, you would need the x and y positions be modified by setters, so you could change a group position relatively (that’s, if the tank and it’s cannon have different dimensions, you would first get the delta and then move both by this delta, instead of positioning both at the new position).

  2. deathray says:

    If you allow for N-textures, then your actor class becomes very versatile. Is there a downside? What are the pros and cons? And what language are you using?

  3. jovoc says:

    Posted a reply to your post on StackExchange. Basically I would be careful of making your Actor class too complicated, you’ll regret it down the road. I would suggest adding some kind of parenting or constraint system and represent the tank as two Actors that are parented or constrained together.

Leave a Reply

You must be logged in to post a comment.

[cache: storing page]