Help with sprite sheet and mesh

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.

Link to the sprite sheet: http://davidwalsh.name/demo/ken.png


--# 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

Here’s a working version:


--# Main
function setup()
    player = Player()
    parameter.integer("offx", 0, player.spriteCols - 1, 0, function()
        player.spriteOffset.x = offx
    end)
    parameter.integer("offy", 0, player.spriteRows - 1, 0, function()
        player.spriteOffset.y = offy
    end)
end

function draw()
    background(40, 40, 50)
    
    player:draw()
end

function touched(touch)
    player:touched(touch)
end

--# Player
Player = class()

function Player:init()
    self.position = vec2(WIDTH / 2, HEIGHT / 2)
    self.texture = readImage("Documents:KenSpriteSheet")
    self.spriteSize = vec2(70, 80)
    self.spriteCols = 7
    self.spriteRows = 10
    self.spriteOffset = vec2(0, 0)
    self.mesh = mesh()
    self.mesh.texture = self.texture
    self.index = self.mesh:addRect(self.position.x, self.position.y, self.spriteSize.x, self.spriteSize.y)
end

function Player:draw()
    self.mesh:setRect(self.index, self.position.x, self.position.y, self.spriteSize.x, self.spriteSize.y)
    self.mesh:setRectTex(self.index, self.spriteOffset.x / self.spriteCols, (self.spriteOffset.y + 1) / self.spriteRows, 1 / self.spriteCols, 1 / self.spriteRows)
    self.mesh:draw()
end

function Player:touched(touch)
    self.position.x, self.position.y = self.position.x + touch.deltaX, self.position.y + touch.deltaY 
end

All you really needed to do was give the texture to the mesh, but I tweaked some things and fixed some bugs with the texture coordinates.

Thank you! I knew it had to be a simple fix.

Edit: altered phrasing

Here is a shader that works with sprite sheets http://codea.io/talk/discussion/5067/sprite-sheet-shader#Item_1

@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

@matox I’m a bit confused… I think you commented at the wrong person, and on the wrong topic.

@SkyTheCoder sorry, the cards were for @Tyson and @dave1707.

@matox Thanks for the cards. Downloaded them with no problems.