Following code draws no sprite at 500,500 but does draw her at 600,600.
-- imagecopy
function setup()
img = readImage(asset.builtin.Planet_Cute.Character_Princess_Girl)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
spriteMode(CENTER)
sprite(img, 500,500)
sprite(asset.builtin.Planet_Cute.Character_Princess_Girl,600,600)
stroke(255)
strokeWidth(3)
noFill()
rectMode(CENTER)
rect(600,600,100,100)
end
OK this is weird. I changed the above program to print(img.width,img.height) and it started to work. Removing the print, it still works. Closing the program, still works.
exiting codea, and it still works. I confess total confusion. Change the sprite referred to, still works. Absolute confusion now.
OK. This code prints false, false. I believe this means that the result of readImage is all zero. And, of course, so is the copy.
Something is borked with `readImage, but it isn’t consistent. My prior example at first did not draw the sprite, then later it did.
-- readCopyImage
function setup()
img = readImage(asset.builtin.Space_Art.Asteroid_Large)
print(checkBits(img))
jmg = img:copy()
print(checkBits(img))
end
function draw()
background(40, 40, 50)
end
function checkBits(anImage)
for x = 1,anImage.width do
for y = 1,anImage.height do
local r,g,b,a = anImage:get(x,y)
if r+g+b+a ~= 0 then return true end
end
end
return false
end
Yes, it’s weird, Dave. It failed, then worked. And there’s no doubt that the shields in Invaders are blank. They are read with readImage and copied with image.copy to get unique copies for each, for individual damage.
-- readCopyImage
function setup()
img = readImage(asset.builtin.Space_Art.Asteroid_Large)
print(checkBits(img))
jmg = img:copy()
print(checkBits(img))
end
function draw()
background(40, 40, 50)
stroke(255)
strokeWidth(2)
noFill()
rectMode(CENTER)
spriteMode(CENTER)
ellipseMode(CENTER)
sprite(img,500,500)
sprite(jmg,600,600)
sprite(asset.builtin.Space_Art.Asteroid_Large,700,700)
ellipse(500,500, 200,200)
rect(600,600, 200,200)
ellipse(700,700,200,200)
end
function checkBits(anImage)
for x = 1,anImage.width do
for y = 1,anImage.height do
local r,g,b,a = anImage:get(x,y)
if r+g+b+a ~= 0 then return true end
end
end
return false
end
readImage seems to work, but :copy messes things up. Run the below code as is. It displays the large asteroid. Tap the screen and the cloudy nebula shows. Uncomment the kmg line and run again. Tap the screen and the nebula shows but the asteroid disappears. Uncomment the lmg line and run. When you tap the screen, everything disappears. The print statements show that the kmg and lmg have values when they’re uncommented.
@Simeon looks like there’s a problem.
PS. This appears to work OK with version 3.2.6 (242).
function setup()
img = readImage(asset.builtin.Space_Art.Asteroid_Large)
print(img)
end
function draw()
background(40, 40, 50)
sprite(img,WIDTH/2,HEIGHT/2+200)
if a then
sprite(jmg,WIDTH/2,HEIGHT/2-200)
end
end
function touched(t)
if t.state==BEGAN then
jmg = readImage(asset.builtin.Space_Art.Cloudy_Nebula)
--kmg = img:copy()
--lmg = jmg:copy()
print("jmg\
",jmg)
print("kmg\
",kmg)
print("lmg\
",lmg)
a=true
end
end
@dave1707@RonJeffies - I can confirm your observations. Tried to see if viewer.mode and blanking out background() had any effect. Also triedsprites from my documents and Dropbox with no change. But measured spriteSize() and that was consistent, copy seemed to work in those terms but no display of the sprites.
Code below, but - I did notice a flash on the screen just after running the project. Think the sprite routine may be at fault or the download of the sprite data.
if it’s just copy, why does the checkbits in my example say there are no bits in img?
-- readCopyImage
function setup()
img = readImage(asset.builtin.Space_Art.Asteroid_Large)
print(checkBits(img))
jmg = img:copy()
print(checkBits(jmg))
end
function draw()
background(40, 40, 50)
stroke(255)
strokeWidth(2)
noFill()
rectMode(CENTER)
spriteMode(CENTER)
ellipseMode(CENTER)
sprite(img,500,500)
sprite(jmg,600,600)
sprite(asset.builtin.Space_Art.Asteroid_Large,700,700)
ellipse(500,500, 200,200)
rect(600,600, 200,200)
ellipse(700,700,200,200)
end
function checkBits(anImage)
for x = 1,anImage.width do
for y = 1,anImage.height do
local r,g,b,a = anImage:get(x,y)
if r+g+b+a ~= 0 then return true end
end
end
return false
end
@RonJeffries - yes and I’ve checked out some of your code and mine on it and it works - but we need to check further and make sure poistioning etc is OK.