开发者

Corona - create regular display objects from sprite sheets?

开发者 https://www.devze.com 2023-02-25 14:07 出处:网络
This is normal way of displaying an image: local 开发者_如何学Goimg = display.newImage(\"image.png\");

This is normal way of displaying an image:

local 开发者_如何学Goimg = display.newImage("image.png");

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

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

EDIT: 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 to http://developer.anscamobile.com/reference/sprite-sheets

0

精彩评论

暂无评论...
验证码 换一张
取 消