Question about using sprites.

I’ve read a document or two about sprites but not really sure how to do this…

I have an idea for a game that involves chucking furniture into a truck using physics.

I’ve attached the sprite sheet so you could better understand what I’m trying to do.

Basically, I want to be able to spawn 1-10 random pieces of furniture onto the screen for the player to throw into a moving truck.

How would I go about using the image sheet to do that? I know how to accomplish this by using a single image file but not a sprite sheet. Also, I tried loading a sprite sheet into a different project (just to learn how to do it) and the background of the sprite showed up along with it. As in…the picture was there but so was the background grid. How do you load only the image and not the background?

Hope I’m making sense lol.

Hi @nickthelibra,

My advice is that you first understand image sheets completely: how to set them up, how to define the frames, and how to pull one frame from the sheet to display on the screen. This guide should get you started:

http://docs.coronalabs.com/guide/media/imageSheets/index.html

Take care,

Brent

 Okay, I read the document but I don’t think I’m setting up my sprite sheet correctly.

What I don’t understand is the dimensions. As in…how to measure each sprites pixels.

I entered the exact dimensions of the image sheet. Since there is 10 images per line, I just divided the X by 10 and the Y by 10 to measure each sprite. But that can’t be the right way because this is what happened [image attached].

It’s not showing the whole couch. Also, when I add physics, there is space around the couch when it hits the ground. Meaning the couch doesn’t touch the floor. Would I have to crop the sprites?

Here is my code:

local tileSet = {

    width = 62.3,

    height = 52.4,

    numFrames = 100,

}

local sheet = graphics.newImageSheet( “/images/furnsprites.png”, tileSet )

local frame1 = display.newImageRect( sheet, 10, 62.3, 52.4 )

frame1.x = display.contentCenterX

frame1.y = display.contentCenterY

Hi @nickthelibra,

My advice is that you first understand image sheets completely: how to set them up, how to define the frames, and how to pull one frame from the sheet to display on the screen. This guide should get you started:

http://docs.coronalabs.com/guide/media/imageSheets/index.html

Take care,

Brent

 Okay, I read the document but I don’t think I’m setting up my sprite sheet correctly.

What I don’t understand is the dimensions. As in…how to measure each sprites pixels.

I entered the exact dimensions of the image sheet. Since there is 10 images per line, I just divided the X by 10 and the Y by 10 to measure each sprite. But that can’t be the right way because this is what happened [image attached].

It’s not showing the whole couch. Also, when I add physics, there is space around the couch when it hits the ground. Meaning the couch doesn’t touch the floor. Would I have to crop the sprites?

Here is my code:

local tileSet = {

    width = 62.3,

    height = 52.4,

    numFrames = 100,

}

local sheet = graphics.newImageSheet( “/images/furnsprites.png”, tileSet )

local frame1 = display.newImageRect( sheet, 10, 62.3, 52.4 )

frame1.x = display.contentCenterX

frame1.y = display.contentCenterY