简体   繁体   English

如何在Android屏幕外的psition上的大位图上绘制小位图?

[英]how to draw a small bitmap on a large bitmap at a psition outside the screen in android?

Assuming that i have an android phone with max x=400 and max y=300 假设我有一个最大x = 400和最大y = 300的android手机

I have a 5000 by 5000 px bitmap and i display a 400 by 300 part of it on screen. 我有一个5000 x 5000像素的位图,并且在屏幕上显示了400 x 300的一部分。 I scroll it around using touch events. 我使用触摸事件来滚动它。 I want to draw a smaller bitmap(30 by 30px) onto that larger bitmap at location (460,370). 我想在位置(46​​0,370)的较大位图上绘制较小的位图(30 x 30像素)。 But i cant statically do it(as my game requires). 但是我不能静态地做到这一点(因为我的游戏要求)。 I want to draw and undraw that smaller image according to the player's input or collision detections. 我想根据玩家的输入或碰撞检测来绘制和缩小该较小的图像。

What i am confused about is that suppose currently (50,50) to (450,350) of the larger image is displayed on the screen and now ,due to a certain requirement of the game at this moment, i have to draw that 30by30 bitmap at (460,370) but this point is in two systems - 1)In the big bitmap's co-ordinate system it's 460,370 but when it will come inside the visible area of screen it will have values something between (0,0) and (400,300) depending upon its position on the screen as per the player's movements... 我感到困惑的是,假设当前在屏幕上显示的是较大图像的(50,50)至(450,350),由于当前游戏的某些要求,我现在必须绘制30by30位图(460,370),但这是在两个系统中-1)在大位图的坐标系中为460,370,但是当它进入屏幕的可见区域时,其值将介于(0,0)和(400,300)之间,具体取决于根据玩家的动作在屏幕上的位置...

So how do i track that image- i mean using which co-ordinate system, and how do i go about doing all this? 那么我如何跟踪该图像-我的意思是使用哪个坐标系,以及如何进行所有这些操作?

I know I've put it here in a very confusing way but that's the best way i can put it and i'll be really glad, and grateful to you if somebody could help me on this..... 我知道我已经以一种非常混乱的方式将其放置在这里,但这是我可以放置它的最佳方式,我将非常高兴,如果有人可以帮助我,我将非常感谢您。

Terminology: 术语:

  • Let's call the coordinates on the big map world coordinates 我们称大地图world coordinates

  • Let's call the coordinates on the screen view coordinates . 我们将其称为屏幕view coordinates You are talking to the drawing system (canvas?) in view coordinates. 您正在与视图坐标中的绘图系统(画布?)交谈。

Your currently displayed region of the bigger map is 100% defined by an offset, let's call this (offsetX, offsetY) . 您当前显示的较大地图区域是由偏移量定义的100%,我们称其为(offsetX, offsetY) Formally, this offset maps your world coordinates onto your view coordinates . 正式地,此偏移量将您的world coordinates映射到您的view coordinates

If you have the small image displayed at position (x, y) in world coordinates, all you need to do is subtract your offset to get to view coordinates, ie 如果您在世界坐标中的(x,y)位置上显示了小图像,则只需减去偏移量即可查看坐标,即

viewX = worldX - offsetX;
viewY = worldY - offsetY;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM