Getting the x y position of an image.

Problems with Canvas, OpenGL, etc...

Getting the x y position of an image.

Postby ekimia » Wed May 26, 2010 11:06 pm

Im working on a scrollable map app (not using mapView for various reasons) and im trying to figure out how would i get the x and y coords of the scrolling bitmap, so i can use a switch and if statements to determine the region. Thanks.
ekimia
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sun May 23, 2010 10:13 pm

Top

Re: Getting the x y position of an image.

Postby IronChef253 » Sat Jun 19, 2010 7:39 am

I could be wrong, but I think it really depends on what method you are using to draw.

If you are using a canvas, I believe you should be wiping out all the data on the screen every frame and then setting the x,y of the bitmap when you redraw the canvas. Basically...you should never need to find out what the x,y are because you are the one setting those variables on draw. It's not like Flash where you can always find out what the x,y of a movieclip is on the stage.

Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);

Therefore, you should have a "Map" class that contains x and y variables to track the bitmap's location on the canvas and then a "Draw(Canvas c)" function that draws the map to the canvas. In addition, you have a Bitmap called myMap or something and if you want to move it, you redraw it in the desired location after the canvas gets cleared.
IronChef253
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jun 13, 2010 6:51 am

Re: Getting the x y position of an image.

Postby ekimia » Sat Jun 19, 2010 4:37 pm

Yeah, thats what I ended up doing mainly. I had a variable tracking how far the bitmap was being scrolled on a canvas, then it was redrawn. To pinpoint a location, i used the screen x an y using event.getRawX etc to determine if the user clicked within the "frame" of the location. The next thing i have to do is make that "frame" in relatives instead of absolutes othewise this app will only work on the droid.


IronChef253 wrote:I could be wrong, but I think it really depends on what method you are using to draw.

If you are using a canvas, I believe you should be wiping out all the data on the screen every frame and then setting the x,y of the bitmap when you redraw the canvas. Basically...you should never need to find out what the x,y are because you are the one setting those variables on draw. It's not like Flash where you can always find out what the x,y of a movieclip is on the stage.

Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);

Therefore, you should have a "Map" class that contains x and y variables to track the bitmap's location on the canvas and then a "Draw(Canvas c)" function that draws the map to the canvas. In addition, you have a Bitmap called myMap or something and if you want to move it, you redraw it in the desired location after the canvas gets cleared.
ekimia
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sun May 23, 2010 10:13 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 6 guests