问题描述
这是显示图像的常规方式:
This is normal way of displaying an image:
local img = display.newImage("image.png");
但它是否会节省内存以将所有图像放在一个大图像中并从Zwoptex导出?有关于从精灵表创建动画精灵的文档,但是从精灵表中提取单个图像呢?
But doesn't it save memory to put all your images in one large image and export from Zwoptex? There is documentation for creating animated sprites from sprite sheets, but what about just pulling a single image from a sprite sheet?
local zwoptexData = require "sheet1"
local data = zwoptexData.getSpriteSheetData()
//then what?
推荐答案
从瓷砖表制作静态图像的命令看起来像这样:
The commands to make a static image from a tile sheet look like this:
local tileSheet = sprite.newSpriteSheet("tiles.png", 64, 64)
local tileSet = sprite.newSpriteSet(tileSheet, 1, 10)
local tile = sprite.newSprite(tileSet)
tile.currentFrame = 5
假设工作表上的所有图块都是64x64,但您可以轻松调整这些命令以使用您的精灵表数据。需要注意的重要事项是newSprite()和.currentFrame
That assumes all the tiles on the sheet are 64x64 but you could easily adapt those commands to use your sprite sheet data. The important things to note are newSprite() and .currentFrame
编辑:您评论说你无法弄清楚如何使用sprite数据,所以修改后的代码是
You commented that you can't figure out how to use sprite data with this, so the modified code is
local data = require("tiles.lua")
local tileSheet = sprite.newSpriteSheetFromData("tiles.png", data.getSpriteSheetData())
local tileSet = sprite.newSpriteSet(tileSheet, 1, 3)
local tile = sprite.newSprite(tileSet)
tile.currentFrame = 2
要了解这是如何工作的,请参考
To learn how this works refer tohttp://developer.anscamobile.com/reference/sprite-sheets
这篇关于电晕 - 从精灵表创建常规显示对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!