绘制的Andr​​oid屏幕上有一个坐标系 [英] Drawing on the android screen with a coordinate system

查看:104
本文介绍了绘制的Andr​​oid屏幕上有一个坐标系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是可能将是最初非常困惑阅读,所以才忍耐一下。我会一点点preface上下文启动它关闭:

My question is probably going to be initially very confusing to read, so just bear with me. I'll start it off with a little preface for context:

preface:

我将使用从地图寻路阵列的应用程序。

I have an app that will be using an array for path-finding from a map.

^这是非常含糊:将有一个字符数组,再presenting墙壁,楼梯等,且有将是找到最佳路径的功能。

^That is very vague: There will be an array of characters, representing walls, stairs, etc., and there will be a function that finds the best path.

我要显示在Android屏幕上的路径。

I want to display the path on the android screen.

有将是是由重新present生成的路径(可能是X或某事)数组函数生成的字符。

There will be characters that are generated by the array function that represent the generated path (probably "x" or something).

好吧,使其更明确:将有一个的'X的阵列中的路径。这些X的重新present就是要告诉了Android屏幕上的路径。

我的实际问题:

如何在数组中翻译为x在屏幕上显示一条线?我有主意,用一个for循环/ if语句检查如果存在一个x并且如果存在,那么,显示该重新presents实际屏幕的第二阵列一个小红点/线。

How do I translate an 'x' in the array to displaying a line on the screen? I had the idea to use a for loop/if statement that checks if there is an 'x' and if there is, then to display a little red dot/line in a second array that represents the actual screen.

我试图找到这一点,但它的这种输入到谷歌尴尬的事情,所以我完成我的研究有什么。

I was trying to find this, but it's such an awkward thing to type into google, so I finished my research with nothing.

是否有某种内置Android功能,您可以分配不同的颜色,以不同的坐标?

这是什么样的我希望出现在屏幕。如果这是应用程序,蓝色将重新通过'X的第一阵列中的psented $ P $。

推荐答案

可以有多种方式来实现具有坐标系映射到描述的路径矩阵的这种效果。

there could be several ways to achieve this effect of having a coordinate system mapping to a matrix that describes a path.

根据数组的大小和更新调用的频率(这听起来像路径以一个单一的渲染后发现运行一次),它可能不会太昂贵,只是遍历。我个人会做的是先来了解一下如何绘制在画布上,得到了屏幕尺寸,并相应地调整范围。

Depending on the size of the array and the frequency of update calls (it sounds like the path finding runs once with a single render after), it probably wouldn't be too expensive to just loop through. What I personally would do is start to look at how to draw on a canvas, get the screen size, and adjust the bounds accordingly.

Android的:如何获得屏幕尺寸 - 如何获取屏幕尺寸
http://danielnadeau.blogspot.com/2012/01/android -canvas初学者-tutorial.html - 在画布上一个不错的教程

Android: How to get screen dimensions - How to get screen dimensions http://danielnadeau.blogspot.com/2012/01/android-canvas-beginners-tutorial.html - A nice tutorial on canvases

一旦你可以画到画布缩放,它只是运行一个循环,看起来像的问题:

Once you can draw to a scaled canvas, it is simply a matter of running a loop that looks something like:

float scale_x = screen_width/columns;
float scale_y = screen_height/rows; //pixels per grid square
for( int x = 0; x < columns; x++)
for( int y = 0; y < rows; y++)
if( data[x][y] == 'x') drawRect(x*scale_x, y*scale_y, scale_x,scale_y) //if something found, draw a colored square

这篇关于绘制的Andr​​oid屏幕上有一个坐标系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆