Why does this just show a white box and not part of the sprite sheet? I’m just trying to draw one of the sprites at first and work my way up to animating.
--# Main
function setup()
player = Player()
end
function draw()
background(40, 40, 50)
player:draw()
end
--# Player
Player = class()
function Player:init()
self.mesh = mesh()
self.texture = readImage("Documents:KenSpriteSheet")
self.spriteSize = vec2(70, 80)
self.spriteCols = 7
self.spriteRows = 10
self.position = vec2(WIDTH / 2, HEIGHT / 2)
end
function Player:draw()
self.mesh:clear()
local index = self.mesh:addRect(self.position.x, self.position.y, self.spriteSize.x, self.spriteSize.y)
self.mesh:setRectTex(index, 1 / self.spriteCols, 1 / self.spriteRows, 1 / self.spriteCols, 1 / self.spriteRows)
self.mesh:draw()
end
function Player:touched(touch)
end
@SkyTheCoder Maybe you can use for your Card Game these cards.
-- A playing card set
-- Use this function to perform your initial setup
function setup()
x=0
imgC={}
imgS={}
imgH={}
imgD={}
for i=1,13 do
imgC[i]=http.request("https://dl.dropboxusercontent.com/u/19857700/C"..i..".png",
function(data,status,headers)imgC[i]=data end)
imgS[i]=http.request("https://dl.dropboxusercontent.com/u/19857700/S"..i..".png",
function(data,status,headers)imgS[i]=data end)
imgH[i]=http.request("https://dl.dropboxusercontent.com/u/19857700/H"..i..".png",
function(data,status,headers)imgH[i]=data end)
imgD[i]=http.request("https://dl.dropboxusercontent.com/u/19857700/D"..i..".png",
function(data,status,headers)imgD[i]=data end)
end
end
-- This function gets called once every frame
function draw()
background(0)
for i = 1,13 do
x=x+50
if imgC[i] ~= nil then sprite(imgC[i],x,500) end
if imgS[i] ~= nil then sprite(imgS[i],x,400) end
if imgH[i] ~= nil then sprite(imgH[i],x,300) end
if imgD[i] ~= nil then sprite(imgD[i],x,200) end
end
x=0
end