Howdy, Stranger!

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

Sprite / asset bug

in Bugs Posts: 789

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

Comments

  • dave1707dave1707 Mod
    Posts: 8,456

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

  • dave1707dave1707 Mod
    Posts: 8,456

    @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
    
  • Posts: 789

    @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

  • Posts: 789

    @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
  • Posts: 789

    @dave1707 I agree it would be good to have somewhere to log these - the issue tracker would make sense but not sure if this is really used

    @Simeon - where is the correct place to log/store these requests? In this forum? In the issue tracker? On discord? On twitter?

  • SimeonSimeon Admin Mod
    Posts: 5,386

    @West any of those are good. Though I'm not as active on Discord as @John is (I'll try to go there more!)

  • SimeonSimeon Admin Mod
    Posts: 5,386

    @West @dave1707 looks like this is an issue with sprite batching

    You can disable sprite batching with the spriteBatching(false) call until I resolve this for next update

  • SimeonSimeon Admin Mod
    Posts: 5,386

    Fixed in the beta of 3.2.4 which will be released shortly

  • Posts: 789

    @Simeon. Thanks for resolving this.

  • Posts: 789

    @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
    
  • dave1707dave1707 Mod
    edited June 21 Posts: 8,456

    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
    
  • Posts: 789

    @dave1707 @Simeon Indeed - but also note it is asset dependent. If you swap the horn girl and guy around then it works fine.

  • dave1707dave1707 Mod
    Posts: 8,456

    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
    
  • SimeonSimeon Admin Mod
    Posts: 5,386

    Thank you both for finding this too, I'll fix it soon

    I'm looking forward to moving to the new Metal renderer @John is working on, it'll replace all of the sprite code internally with something more solid

  • SimeonSimeon Admin Mod
    Posts: 5,386

    @dave1707 @West negative dimension bug is fixed in the latest build. Thanks again

  • dave1707dave1707 Mod
    Posts: 8,456

    @Simeon The bug is fixed ( ver 3.2.4 (232) ). I couldn’t get it to mess up using the above code trying all the different combinations.

  • Posts: 789
    Great - thx
Sign In or Register to comment.