Came across this odd behaviour when trying to use sprite sheets. The second sprite call seems to be ignoring the contents and referring to the first
-- Asset Tester
-- Use this function to perform your initial setup
function setup()
fc=0
local myImage=readImage(asset.builtin.Environments.Sunny_Up)
frames={}
for i=6,0,-1 do
fc=fc+1
frames[fc]={}
for j=0,3 do
table.insert(frames[fc],myImage:copy(j*25,i*25,25,25))
end
end
curframe=1
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
sprite(frames[3][math.floor(curframe)],WIDTH/2,HEIGHT/2)
curframe = curframe + 0.1
if curframe>=5 then curframe=1 end
sprite(asset.builtin.Blocks.Brick_Grey,WIDTH/2,HEIGHT/2-128)
end
@West This problem or a similar one has been posted awhile ago. Not sure why it hasn’t been fixed yet. Maybe @Simeon forgot about it or didn’t see it. @Simeon, can a sticky discussion be put at the top of the discussion list where users can post/see any bugs easily. I know there’s an Issue Tracker at the top, but I don’t think anyone uses it. It’s easier just to post an example of a problem in a discussion. Users can easily look thru the list and as you fix a problem, you can add a comment.
@West@Simeon Here’s a simpler example. It seems the readImage is the problem. Run the below code and 2 different sprites show (Boy and Star). Uncomment the readImage line and the same sprite shows (Boy) in both places.
displayMode(FULLSCREEN)
function setup()
myImage=asset.builtin.Planet_Cute.Character_Boy
--myImage=readImage(asset.builtin.Planet_Cute.Character_Boy)
end
function draw()
background(0)
sprite(myImage,WIDTH/2,HEIGHT/2+100)
sprite(asset.builtin.Planet_Cute.Star,WIDTH/2,HEIGHT/2-100)
end
@dave1707@Simeon I have a more complicated version where the issue resolves itself after certain actions but can’t figure what is the trigger. Can post the code tomorrow if that will help
@dave1707@Simeon I’ve managed to recreate the “fix”. Touching the screen sets a flag to true which causes the if statement to resolve which corrects all images. Interestingly if you set touchflag to true from the get go then the images draw correctly.
displayMode(FULLSCREEN)
function setup()
myImage=asset.builtin.Planet_Cute.Character_Boy
myImage=readImage(asset.builtin.Planet_Cute.Character_Boy)
touchflag=false
end
function draw()
background(0)
sprite(myImage,WIDTH/2,HEIGHT/2+100,100,100)
sprite(asset.builtin.Planet_Cute.Star,WIDTH/2,HEIGHT/2,100,100)
if touchflag then
sprite(asset.builtin.Planet_Cute.Heart,WIDTH/2,HEIGHT/2+300,100,100)
end
end
function touched(t)
if t.state==ENDED then
touchflag=true
end
end
@Simeon following up on this, spriteBatching doesn’t resolve the following - one asset set (the platformer) doesn’t like the sprite to be flipped horizontally. Running as written renders the guy as the horned girl. Uncommenting spriteBatching doesn’t render the guy sprite at all. Commenting in the first guy sprite also doesn’t work, but having all 4 but no spriteBatching works as it should do.
I’m assuming entering a negative width in the dimensions of sprite is meant to flip the image (I’ve always assumed that it was supposed to work this way). Can you check this functionality works correctly with the new beta please
-- Platform Art Flip
-- Use this function to perform your initial setup
function setup()
-- spriteBatching(false)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
-- Try combinations of commenting out the following along with spriteBatching in setup
-- sprite(asset.builtin.Platformer_Art.Guy_Look_Right,500,300,100,100)
sprite(asset.builtin.Platformer_Art.Guy_Look_Right,500,200,-100,100)
sprite(asset.builtin.Planet_Cute.Character_Horn_Girl,700,300,100,100)
sprite(asset.builtin.Planet_Cute.Character_Horn_Girl,700,200,-100,100)
end
Version 3.2.4 doesn’t fix everything. This code works. If you put a negative sign on the first sprite, it’s messed up. Also, uncommenting the spriteBatching changes things. Using a negative sign was a way to flipped or rotated the sprite for as long as I remember. This is a stripped version of the above code.
function setup()
--spriteBatching(false)
end
function draw()
background(40, 40, 50)
sprite(asset.builtin.Platformer_Art.Guy_Look_Right,WIDTH/2,500,100,100)
sprite(asset.builtin.Planet_Cute.Character_Horn_Girl,WIDTH/2,300,100,100)
sprite(asset.builtin.Planet_Cute.Character_Horn_Girl,WIDTH/2,100,-100,-100)
end
I switched the girl and guy sprites. Put a negative sign on the first Guy and it flips OK. Then put a negative sign on the second Guy, not OK. The uncomment the spriteBatching line.
function setup()
--spriteBatching(false)
end
function draw()
background(40, 40, 50)
sprite(asset.builtin.Planet_Cute.Character_Horn_Girl,WIDTH/2,700,100,100)
sprite(asset.builtin.Platformer_Art.Guy_Look_Right,WIDTH/2,500,100,100)
sprite(asset.builtin.Platformer_Art.Guy_Look_Right,WIDTH/2,300,100,100)
end