SVG object from x/y coordinate

  ... the SVG Extension for AndEngine.

SVG object from x/y coordinate

Postby armand123 » Fri Oct 21, 2011 8:00 pm

Hi,

first i decide to implement my game with TMX but now i want switch to SVG.
Currently I'm looking for the way how i can retrieve an object inside the SVG graphic depend on x/y coordinates. I must know when the player touch the screen what SVG object he touched. Something like
TMXTile tile = tmxLayer.getTMXTileAt(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());

Is there a way? Thanks for help.
When i solve this problem i can start implement my game. I test now some weeks the features of AndEngine and i have all pieces of the puzzle(scrolling, zooming etc.) expected this one.

Regards
Armand
armand123
 
Posts: 3
Joined: Fri Oct 21, 2011 7:44 pm

Re: SVG object from x/y coordinate

Postby Mathew » Sat Oct 22, 2011 2:56 pm

If you are using bodys for those tiles, you can use: setUserData("testId")

And than in ContactListener check what is user data of touched tile
User avatar
Mathew
 
Posts: 1073
Joined: Sun Jul 31, 2011 2:49 pm
Location: Tarnów, Poland

Re: SVG object from x/y coordinate

Postby armand123 » Sun Oct 23, 2011 9:51 am

Hi Mathew,

could you give me an example. I found ContactListener in PhysicWorld, do you mean that?

Let me explain detailed what i search for:
I want to build a race game and the race track is an SVG image with backgound tree's etc. The main race track is an filled polygon inside the SVG image and when the user click on the SVG image i must know if he clicks inside the filled polygon.

Regards
armand123
 
Posts: 3
Joined: Fri Oct 21, 2011 7:44 pm

Re: SVG object from x/y coordinate

Postby Mathew » Sun Oct 23, 2011 8:28 pm

Example of contact listener:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         private ContactListener contactListener()
  2.         {
  3.             ContactListener contactListener = new ContactListener()
  4.             {
  5.                 @Override
  6.                 public void beginContact(Contact contact)
  7.                 {                      
  8.                                 final Fixture x1 = contact.getFixtureA();
  9.                                 Fixture x2 = contact.getFixtureB(); //player
  10.                        
  11.                                
  12.                                 if (x1.getBody().getUserData() != null)
  13.                                 {
  14.                                         if (x1.getBody().getUserData().equals("yourTag"))
  15.                                         {
  16.                                                 //action
  17. }
  18.  
  19. //rest unimplemented methods from contact listener here.
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


And you can 'Tag' your body/fixture by setting user data.

setUserData("yourTag");
User avatar
Mathew
 
Posts: 1073
Joined: Sun Jul 31, 2011 2:49 pm
Location: Tarnów, Poland

Re: SVG object from x/y coordinate

Postby armand123 » Sat Oct 29, 2011 10:50 am

Thanks Mathew.
Now I know what you mean. It was my fault, I only see the AndEngine SVGTextureRegion Extension.
I don't see the SVGLoader Extension because it's not on the main AndEngine Extension page.

But now after some tests with the SVGLoader extension i decide to use a combination from SVGTextureRegion Extension and invisible TMX. Thats seemed to be the easiest way for my app.
armand123
 
Posts: 3
Joined: Fri Oct 21, 2011 7:44 pm


Return to SVG

Who is online

Users browsing this forum: No registered users and 2 guests