User Tools

Site Tools


en:examples:objects:counting_objects_by_name

Counting Objects by Name

How to get a count of all objects with a particular name. In this case, both the ship and invader carry a bullet. This example counts all the BulletObjects.

Assets

Code

	int bulletObjectCount = 0; 
 
	orxSTRUCTURE *objectToCheck = orxStructure_GetFirst(orxSTRUCTURE_ID_OBJECT);
	while (objectToCheck != orxNULL){
		const orxSTRING name = orxObject_GetName(orxOBJECT(objectToCheck));
 
		if (orxString_Compare(name, "BulletObject") == 0){
			bulletObjectCount++;
		}
 
		objectToCheck = orxStructure_GetNext(objectToCheck);
	}
 
	//bulletObjectCount contains the total amount of active BulletObject(s).

Config

[ShipObject]
Graphic = ShipGraphic
Position = (150, 150, -0.1)
ChildList = BulletObject
 
[InvaderObject]
Graphic = InvaderGraphic
Position = (250, 150, -0.1)
ChildList = BulletObject
 
[BulletObject]
Graphic = BulletGraphic
Position = (0, 8, -0.1)
 
[ShipGraphic]
Texture = ship.png
Pivot = center
 
[InvaderGraphic]
Texture = invader.png
Pivot = center
 
[BulletGraphic]
Texture = spawner-bullet.png
Pivot = center

en/examples/objects/counting_objects_by_name.txt · Last modified: 2020/08/19 19:40 (4 years ago) by sausage