Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Objects list : How to use it?
#1
I want to put some objects in my world and make them spawn on screen and self-destruct outside the screen

But I don't understand how to use theses list. Can you explain clearely how can I achieve that please? I know I have to code functions that inserts and remove objets from the list but that's all
Reply
#2
Hi,

This is a gameplay mechanic topic. Tilengine itself is a graphics engine, no a full game engine, so it doesn't provide direct support for things like actors or game entities. This is something you must provide in your game code. However, this is a basic approach:

Define your basic game entity -the "actor"-. It can be a hierarchy of classes or a simple structure, whatever you decide. It depends on type of game being designed, but typical properties are:
  • type
  • position
  • speed/direction vector
  • life/health
  • state
  • assigned sprite(s)
Have a list of "spawn points" of your map. This can be loaded and retrieved with tilengine object list API (TLN_LoadObjectList, TLN_GetListObject)
Have a list of active actors. This list is empty at the beginnig.

At each frame, search list of spawn points and find which one(s) is candidate for spawn:
  • it is near the edge of the screen you're moving too
  • it's not already in the "active actors" list.
When you have found one spawn candidate:
  • create an actor instance of the type, initialize and assign required sprite(s)
  • add the instance to your list of active actors.
You have a working example of this in Python platformer project:
https://github.com/megamarc/TilenginePythonPlatformer

Let me know
Reply
#3
So if I understand well, I have to provide to TLN_LoadObjectList a tilemap file and a layer name?

My object Layer is stored with a tilemap layer in Tiled, so I have to provide this tilemap layer with the name of this object layer?
Reply
#4
If you just want to use an object list as non-interactive "decorations", Tilengine can draw them by itself. To see a working example, chech the sample "forest" and its related assets:
https://github.com/megamarc/Tilengine/bl...s/Forest.c

The graphic objects must be stored bitmap-based Tiled .tsx file.

Check guide here:
http://www.tilengine.org/doc/md_layers.h...totoc_md31

  1. Load the object layer with TLN_LoadObjectList()
  2. Assign to a layer with TLN_SetLayerObjects()
However, if you want to use the object list for own-purpose gameplay mechanics -like spawning sources for actors- it's up to you to query the list and operate accordingly, as I outlined in previous post.
Reply
#5
The function TLN_Init() asks for a number of sprites, what is it for?
Reply
#6
Sprites in Tilengine are statically allocated during init, you set the maximum number of sprites the engine will manage. All sprite functions take an index number indicating which sprite are you dealing with. Background layers work this way too. This is to mimick actual 2D graphic chips, where sprites and layers are hardware slotted and you don't create or destroy them, but instead you enable/configure them.

The sega megadrive/genesis has 80 sprites, the super nintendo/famicom 128, and the NeoGeo has 380 -but no background layers-, to give you an idea.
Reply
#7
And is that related to the objects list?
Reply
#8
No, they're unrelated. Object list can have an arbitrary number of items, and are related to background layers, not to sprites.
Reply
#9
and if I understand well, if an object (an ennemy for exemple) creates another object (a bullet for exemple), this bullet goes in this list?
Reply
#10
Yes, each created entity must go to the list of active actors, that must be processed each frame. And when you delete an actor, release its resources (for example its assigned sprite) and remove it from the list.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)