Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sprite Bug

edited June 2014 in Bugs Posts: 425

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

Comments

  • dave1707dave1707 Mod
    Posts: 7,753

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

  • dave1707dave1707 Mod
    edited June 2014 Posts: 7,753

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

  • dave1707dave1707 Mod
    Posts: 7,753

    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.

  • dave1707dave1707 Mod
    edited June 2014 Posts: 7,753

    @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
  • Posts: 1,976

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

    img = readImage("Platformer Art:Monster Moving", 60, 32)
    
  • dave1707dave1707 Mod
    Posts: 7,753

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

  • Jmv38Jmv38 Mod
    Posts: 3,295

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

  • Posts: 425

    thanks for the suggestions guys

  • dave1707dave1707 Mod
    Posts: 7,753

    @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.

  • Jmv38Jmv38 Mod
    Posts: 3,295

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

    translate(x,y)
    scale(sx,sy)
    sprite(xxx)
    
  • Jmv38Jmv38 Mod
    Posts: 3,295

    @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.

Sign In or Register to comment.