6. Hit with psd image

Chapters

            Main image format in ARSA Framework is Photoshop format (psd). Query information hit with touch coordinate, hit with other psd layer or hit with line and box can done by code api.

            6.1 Hit with touch coordinate

                        6.1.1 Get touch coordinate (section 5.2.1 C.)

                        6.1.2 Call hit() (more info please see api ref)

                                    A.) Query by touch coordinate, All visible layers in psd file will check hit with x and y axis.

int x = g_input->getTouchX(0);

int y = g_input->getTouchY(0);

int id = g_psd->hitXY(x, y);

if (id != -1)

{

       // hit some layer in psd file, use id for operation.

}

                                    B.) Query by layer name. (B1 and B2 are equal)

                                    B1.)

int x = g_input->getTouchX(0);

int y = g_input->getTouchY(0);

if (g_psd->hitXYLayer(x, y, "boss"))

{

       // boss layer hit current touch coordinate

}

                                    B2.)

int x = g_input->getTouchX(0);

int y = g_input->getTouchY(0);

int id = g_psd->getPsdId("boss");

if (g_psd->hitXYId(x, y, id))

{

       // boss layer hit current touch coordinate

}

                        C.) Query by keep all layers id hit.

int x = g_input->getTouchX(0);

int y = g_input->getTouchY(0);

irr::core::array<irr::s32> outHits;

if (g_psd->hitXYs(x, y, outHits) > 0)

{

       // array outHits keep all hit layer id

}

                    D.) Query by prefix, search hit layer and path of layer name must same parameter.

int x = g_input->getTouchX(0);

int y = g_input->getTouchY(0);

if (g_psd->hitXYPrefix(x, y, "enemy"))

{

       // all enemy layer hit current touch coordinate

}

                        E.) Query by keep all layers id hit and have prefix same parameter.

int x = g_input->getTouchX(0);

int y = g_input->getTouchY(0);

irr::core::array<irr::s32> outHits;

if (g_psd->hitXYPrefixs(x, y, "enemy", outHits) > 0)

{

       // array outHits keep all layer id that hitty and have path of layer name same parameter.

}

              6.2 Hit with psd structure

                        6.2.1 Get psd structure

int id = g_psd->getPsdId("boss");

const irr::arsa::SPsd& boss = g_psd->getPsd(id);

                         6.2.2 Call hit() (A1 and A2 are equal)

                                    A1.)

int hit_id = g_psd->hit( boss );

if ( hit_id != -1 )

{

       // boss layer hit some layer in g_psd

}

                                    A2.)

int hit_id = g_psd->hit( id );

if ( hit_id != -1 )

{

       // boss layer hit some layer in g_psd

}

                         6.2.3 Query by keep all layers id hit.

irr::core::array<irr::u32> outHits;

if (g_psd->hit(boss, outHits)>0)

{

       // array outHits keep all hit layer id

}

 

                         6.2.4 Query hit with other psd image. If user have multiple psd files and want to query with another psd do the following:

// declare as global var

irr::arsa::CARSAPsd* g_player = 0;

// write at init function

// load player.psd

g_player = arsa_AddARSAPsd(g_smgr);

g_player->load("player.psd");

// write at update function

// get player id from g_player or player.psd

int player_id = g_player->getPsdId("player");

// get psd structure by player id

const irr::arsa::SPsd& player = g_player->getPsd(player_id);

// use g_psd as main point for search what layer hit with player

int hit_id = g_psd->hit(player);

if (hit_id != -1)

{

}

           6.3 Hit with line

                        6.3.1 If found hit layer then return

// 1, 1, 1 is start point x, y, z

// 100, 100, 1 is end point

// always set z is 1 because we in 2d mode

irr::core::line3df line(1, 1, 1, 100, 100, 1);

int hit_id = g_psd->hitLine(line);

if (hit_id != -1)

{

       // line hit some layer

}

                        6.3.2 Hit by specify layer id

Int id = g_psd->getPsdId("boss");

irr::core::line3df line(1, 1, 1, 100, 100, 1);

if (g_psd->hitLine(line, id))

{

       // line hit boss layer

}

                        6.3.3 Hit search all layer hit with line

irr::core::line3df line(1, 1, 1, 100, 100, 1);

irr::core::array<irr::s32> outHits;

if (g_psd->hitLine(line, outHits)>0)

{

       // array outHits keep all hit layer id

}

           6.4 Hit with box

// 5, 5, 1 is min axis of box

// 10, 10, 1 is max axis of box

// always set z is 1 because we in 2d mode

irr::core::aabbox3df box(5, 5, 1, 10, 10, 1);

int id = g_psd->getPsdId("boss");

if (g_psd->hitBox(box, id))

{

       // hit with box

}

          6.5 Hit with Touch

                      6.5.1 Touch input hit layer name. 

irr::core::stringc name = g_psd->hitTouch(irr::EKS_DOWN);

if (!name.empty())

{

       // hit some layer when press down

}

                      6.5.2 Touch input hit specify layer name. 

if (g_psd->hitTouchLayer("boss", irr::EKS_DOWN))

{

       // hit boss layer when press down

 

}

                      6.5.3 Touch input hit layer name have path of name same parameter. 

int id = g_psd->hitTouchPrefix("enemy", irr::EKS_DOWN);

if (id != -1)

{

       // hit layer name have a path same parameter.

}

                        6.5.4 Touch input return hit layer name 

irr::core::stringc name = g_psd->hitTouch(irr::EKS_DOWN);

if (!name.empty())

{

       // hit some layer when press down

}

                      6.5.5 Touch input hit layer name and keep all layers id that have path of name same parameter. 

irr::core::array<irr::s32> outHits;

if (g_psd->hitTouchPrefixs("enemy", irr::EKS_DOWN, outHits) > 0)

{

       // hit some layer when press down

}

 

          6.4 Conclusion

                        User can use hit api for query information with touch, psd structure, line and box. Hit come with various parameters maybe you must check your requirement before call hit following table1.

Table1: Hit Index

Hit requirement

Section.

Hit with touch coordinate

6.1

Hit with psd structure

6.2

Hit with line

6.3

Hit with box

6.4

 

API Reference:

http://sarosworld.com/arsasdk

 

Tags: