User Tools

Site Tools


en:tutorials:colliding_scrollobjects_with_orxobjects

Colliding ScrollObjects with Orx Objects

ScrollObject classes provides a lot of functionality and organisation for projects by wrapping the existing Orx object.

For testing collisions between one ScrollObject and another, the class provides the OnCollide function eg:

orxBOOL Truck::OnCollide(ScrollObject *_poCollider, 
	const orxSTRING _zPartName, 
	const orxSTRING _zColliderPartName, 
	const orxVECTOR &_rvPosition, 
	const orxVECTOR &_rvNormal)
{
	if (_poCollider == orxNULL) {
		return orxTRUE;
	}
 
}

The OnCollide in this Truck ScrollObject class will detect collisions with another ScrollObject. This expects that any Orx object in your game be wrapped in a ScrollObject class. However, this is not necessary.

You may have many simple Orx objects in your game like Rocks, or Ice, bullets that you wish to collide with your Truck. But it would be very heavy handed to have to create a ScrollObject class for each, especially if the classes are basically empty.

Fortunately, Orx allows you to declare an object in your config to be a ScrollObject. If you had a Rock object defined as:

[Rock]
Graphic = RockGraphic

You can convert it with: @ScrollObject.

[Rock@ScrollObject]
Graphic = RockGraphic

From here, _poCollider in the OnCollide function will be able to contain the Rock ScrollObject if it collides with the Truck.

Brilliant.

en/tutorials/colliding_scrollobjects_with_orxobjects.txt · Last modified: 2018/02/14 04:46 (3 months ago) by iarwain