Sprite Bug

When i run this code (yes the widths are negative on purpose) it draws the same sprite both times even though a different name is specified. I have had this issue only with the vector sprites

function draw()
    background(127, 127, 127, 255)
    spriteMode(CENTER)
    sprite("Platformer Art:Monster Moving",300,300,-100,100)
    sprite("SpaceCute:Beetle Ship",500,300,-100,100)
end

If you make the -100 a positive 100, it works. What’s the purpose of the negative.

OK, the negative reverses the sprite. Apparently it doesn’t work for vector sprites. Take the negative off the vector sprite.

You can use setContext and draw the vector sprite into an image and then you can sprite the image with a negative value to reverse it.

@Coder Here’s an example.

EDIT: Modified the code to use the suggestion by @SkyTheCoder given below.


function setup()
    img=readImage("Platformer Art:Monster Moving")
end

function draw()
    background(127, 127, 127, 255)
    sprite("SpaceCute:Beetle Ship",400,400,-100,100)
    sprite(img,200,400,-100,100)
    
    sprite("SpaceCute:Beetle Ship",400,200,100,100)
    sprite(img,200,200,100,100)
end

@dave1707 Instead of usng setContext, you can use readImage(), i.e.

img = readImage("Platformer Art:Monster Moving", 60, 32)

@SkyTheCoder Thanks. Wasn’t paying to much attention to what I was doing.

i think if you want to flip the image, you can do it with scale(-1,1)

thanks for the suggestions guys

@Jmv38 Scale works, but when using a negative scale factor, the matching x or y value needs to be negative also for it to display in the correct position. While it can be done, it’s probably easier to use the image route.

@Dave1707 right. Actually ok for me, cause most of the time i use

translate(x,y)
scale(sx,sy)
sprite(xxx)

@Dave i’ve just noticed the following in cargo-bot

-- flips along the x-axis
function RectObj:flipX()
    self.x = self.x + self.w
    self.w = self.w * (-1)
end

so it seem the ‘good’ way is with negative w, as you did.