Layer and Frame?

Started by
7 comments, last by BirdGB 9 years, 10 months ago

Hi,

I am making a small game, where, now I want to implement layer and frame. Something like timeline. Each scene will consists of some layer and each layer will have some frames. Each frame will be used as a level and each layer will decide which entity will be visible. If a layer is invisible, all the entity belongs to that layer will be invisible.

I just need some idea how do I implement them! As a class, struct or vectors etc. I only need idea, nothing else.

Thank you.

Advertisement

I'm not sure I understand what you mean. Could you try re-explaining it another way? Maybe do a very rough mockup in MS Paint to help me understand it better?

I just need some idea how do I implement [layers and frames]! As a class, struct or vectors etc. I only need idea, nothing else.


This doesn't sound like a Game Design question. I'm moving it elsewhere.

-- Tom Sloper -- sloperama.com

Sorry for not explaining clearly. Generaly a timeline looks like this -

http://wam.inrialpes.fr/publications/2003/smileurope_editingtimelines/timeline_view.png

I also want something like this, but it will not be visible graphically in my game. It will only work internally. What I wanted to do is, load the resources at the initialization and setup all the levels at the same time, frame by frame. Each frame will be a separate level. And during runtime, just change the frame to change the level. Each level will have some layers, which will decide the visibility of the entities. What I wanted to know is, how do I implement them, as a class, as a struct, as a vector or something else. A simple example will be, Flash actionScript 2. The levels are created frame by frame during initialization and nothing is freed/loaded during runtime.

I think you need to specify what exactly some of your concept keywords actually means. We can't help you if we don't understand your concept of:

  • Level
  • Frame
  • Layer

as a class, as a struct, as a vector or something else.


All of the above? It's not going to be "a" class or "a" vector. You're asking for a syntactical solution to a complex question of data structures and algorithms.

A typical way of dealing with this is keeping a list of events. For instance, something like:

enum class FrameEventTypes
{
  Show,
  Hide,
};

struct FrameEventRecord
{
  double time =0.0; 
  int layerId = 0;
  FrameEventTypes type = FrameEventTypes::Show;
};

class Frame
{
  vector<Layer> layers;
  vector<FramgEventRecord> events;
  double time = 0.0;
  size_t next = 0;

  void ExecuteEvent(size_t index);

public:
  void Update(double delta_time);
};
The list of events is sorted in order of `time`. Then you iterate over the list of events with a delta time and execute them as needed:

void Frame::Update(double dt)
{
  time += dt;
  while (next < events.size() && events[next].time <= time)
    ExecuteEvent(next++);
}

void Frame::ExecuteEvent(size_t index)
{
  switch (events[index].type)
  {
  case FrameEventTypes::Show:
    layers[events[index].layer].Show();
    break;
  case FrameEventTypes::Hide:
    layers[events[index].layer].Hide();
    break;
  }
}
And then you can add in more events as needed. You might have events to add or remove elements, show or hide individual elements, play sounds, run animations, whatever.

Sean Middleditch – Game Systems Engineer – Join my team!

It is a 2d game. So basically what I am trying to do is, rather then making game states and clrearing/loading the game resources during runtime, I am thinking to load everything at the application start and set all levels frame by frame. Then when I have to change the level, I will just skip the frame. I have implemented the scene, resource loading etc, now I have to implement only the layer and frames. it is like -

Scene -- Layers -- Frames

If I hide one layer, every entity belongs to that layer will hide and remain invisible to all frames(levels).

Thank you for your reply.

You are over-thinking this. If for some reason you need to load everything at startup (highly unlikely actually but hey-ho) then design your architecture so that any given level or however you compartmentalise is stored in some kind of structure hierachy - e.g. a Level class, containing a list of Entity instances etc.

All the code then uses a reference to the current structure. You can load all the structures at startup and just change this reference when you want to switch levels.

All this hokum about layers and frames is entirely distracting from a far simpler question.

I have already implemented this and it is working as expected :)

Thanks for the reply.

This topic is closed to new replies.

Advertisement