简体   繁体   English

设计小地图:更有效的方法

[英]Designing minimaps: the more efficient way to do it

Am am making a wap-game that will have a minimap. 我正在制作一款带有小地图的wap游戏。 It is basically a 5x5 div with (a) 20x20 pixel background image(s). 它基本上是一个5x5的div,具有(一个)20x20像素的背景图像。

I've come to a stalemate trying to figure out on how to design them, though. 不过,我陷入僵局,试图弄清楚如何设计它们。

Making a 100x100 pixel image for each 'location' wouldn't be a good idea, since if one of those 20x20 locations changed, I would have to update 15 100x100 images. 为每个“位置”制作一个100x100像素的图像不是一个好主意,因为如果更改了这20x20位置之一,我将不得不更新15张100x100图像。

Two choices are left then: 剩下两个选择:

  • Combining the 20x20 pixel images to a big 100x100 pixel one using GD 使用GD将20x20像素的图像合并为100x100像素的大图像
  • Giving each div in the minimap a background with the 20x20 location image. 给小地图中的每个div加上20x20位置图像的背景。

In the second scenario a lot of HTTP requests would me made to fetch the images, in the first, server resources would be used to combine them to a big image. 在第二种情况下,我会发出很多HTTP请求来获取图像,在第一种情况下,将使用服务器资源将它们组合成一个大图像。

Which of the options do you think would be a more efficient one? 您认为哪种选择更有效? Basically I see it as a lose-lose situation, but one has to decide which loss is less painful. 基本上,我认为这是一种失败的情况,但是必须决定哪种损失不会那么痛苦。

Why don't you check out CSS SPRITES? 您为什么不签出CSS SPRITES?

http://spriteme.org/ http://spriteme.org/

Then you can generate the map with a php function that select the CSS class (with its relative background) randomly. 然后,您可以使用php函数生成地图,该函数随机选择CSS类(及其相对背景)。

If you have let's say 9 different parts of map 20x20, to be combined in a 3x3 grid, you just have to create a class for each piece of map. 如果您假设将20x20地图的9个不同部分组合成3x3网格,则只需为每张地图创建一个类。 You can generate it dinamically (replace 0px 0px with a "$x = rand(0,3)*20; $y = rand = rand(0,3)*20;" or so. 您可以动态生成它(用“ $ x = rand(0,3)* 20; $ y = rand = rand(0,3)* 20;”替换0px 0px左右)。

.map1 {
    background-image:url(/images/css_sprite.png);
    background-position:0px 0px;
    background-size:20px 20px;
}

1 HTTP request to be called, and no server resources to be wasted in GD! 1个HTTP请求被调用,GD中没有服务器资源被浪费!

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

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