Howdy, Stranger!

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

Sprite Bug

edited August 2013 in Bugs Posts: 59

I had a sprite set to a certain image, and the I changed it but it was still drawing the previous image.

Comments

  • Posts: 1,976

    Please be more specific. What do you mean you had it set, what do you mean you changed it, and what do you mean it was still drawing the previous image? Any chance of seeing your code?

  • I told it to draw a robot. Then I changed it to draw a ball, but it was still drawing the robot.

  • edited August 2013 Posts: 59

    Now it's working, but that was what was happening.

  • edited August 2013 Posts: 1,976

    Code?

    Edit: Oh.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @EpicPotato - please post code.

    99% of the time, it's a bug in the code, not in Codea.

  • And now it won't draw the sprite at the right size.

  • Posts: 1,976

    Code, please?

  • But now it's working. It seems to be a problem where Codea is not saving very quickly.

  • Posts: 1,976

    Please post the code, Codea should save the code instantly once you press run.

  • edited August 2013 Posts: 59
    --# Main
    
    function setup() 
        parameter.watch(PlayerY) 
        displayMode(FULLSCREEN_NO_BUTTONS)
        supportedOrientations(LANDSCAPE_ANY) 
        floor1 = physics.body(EDGE,vec2(-500,HEIGHT/2 - 200),vec2(1000,HEIGHT/2 - 200)) 
        floor2 = physics.body(EDGE,vec2(500,HEIGHT - 200),vec2(1000,HEIGHT - 200)) 
        Player = physics.body(CIRCLE,20)
    
        -- moved the following line from draw
        Player.x = WIDTH/2 Player.y = HEIGHT/2 floor1.x = 500
    
        physics.gravity(0,-400)     -- changed
        parameter.watch("PlayerX") 
        parameter.watch("PlayerY") 
         parameter.watch("Floor1Y") 
        floor1.linearVelocity = vec2(-200,0) 
        Scene = 1 
        scrollTitleScreen = 0 
        xVel = 0 
        yVel = 0 
        physics.friction = .9
    end
    
    function draw()
        --Draws the appropritate stagese
        --Scenes:
        --1 = Title Screen
        --2 = Gamemode Select
        --3 = Stage select
        --4 = Ingame
        scene = Scene
        PlayerX = Player.x
        PlayerY = Player.y -234
        Floor1Y = floor1.y
        textMode(CENTER)
        Player.restution = 1
        floor1.restution = 0.4
    
        -- moved this line to setup
        --Player.x = WIDTH/2 Player.y = HEIGHT/2 floor1.x = 500
    
        if Scene == 1 then 
            strokeWidth(5) 
            background(0, 255, 251, 255) 
            font("Copperplate-Bold") 
            fill(0, 0, 0, 255) 
            fontSize(87) 
            text("THE PROTO PROGRAM",WIDTH/2,HEIGHT -78) 
            rectMode(CENTER) 
            fill(0, 255, 251, 255) 
            stroke(0, 0, 0, 255) 
            rect(WIDTH/2,HEIGHT/2,250,126) 
            fill(0, 0, 0, 255) 
            fontSize(60) text("PLAY",WIDTH/2,HEIGHT/2)
        elseif Scene == 2 then
            strokeWidth(5)
            fontSize(84)
            stroke(0, 0, 0, 255)
            fill(51,51,51,255)
            background(0,255,251,255)
            rectMode(CENTER)    
            fill(0, 0, 0, 255)
            text("CHOOSE A GAMEMODE",WIDTH/2,HEIGHT -78)
            fill(0, 255, 251, 255)
            rect(WIDTH/2,HEIGHT/2,250,126) 
            fontSize(27)
            fill(0,0,0,250)
            text("DEATHMATCH",WIDTH/2,HEIGHT/2)
            rectMode(CORNER)
            fill(0, 255, 251, 255)
            rect(-3,-3,100,50)
            rectMode(CENTER)
            textMode(CORNER)
            fontSize(25)
            fill(0, 0, 0, 255)
            text("BACK",9,10)
       elseif Scene == 3 then
            background(0,255,251,255)
            strokeWidth(5)
            fontSize(84)
            stroke(0, 0, 0, 255)
            background(0,255,251,255)
            rectMode(CENTER)
            fill(0, 0, 0, 255)
            text("CHOOSE A STAGE",WIDTH/2,HEIGHT -78)
            fill(0, 255, 251, 255)
            rect(WIDTH/2,HEIGHT/2,250,126) 
            fontSize(49)
            fill(0,0,0,250)
            text("METRO",WIDTH/2,HEIGHT/2)
            rectMode(CORNER)
            fill(0, 255, 251, 255)
            rect(-3,-3,100,50)
            rectMode(CENTER)
            textMode(CORNER)
            fontSize(25)
            fill(0, 0, 0, 255)
            text("BACK",9,10)
    
       elseif Scene == 4 then
            rectMode(CENTER)
            stroke(0, 0, 0, 255)
            fill(127, 127, 127, 255)
            strokeWidth(5)
            fontSize(84)
            stroke(0, 0, 0, 255)
            background(35, 47, 47, 255)
            rectMode(CENTER)
            fill(0, 0, 0, 255)
             rect(floor1.x,220,1200,90)
            rect(floor2.x + 1080,570,1200,20)
            fontSize(49)
            fill(0,0,0,250)
            rectMode(CORNER)
            fill(0, 255, 251, 255)
            rect(-3,-3,200,100)
            rectMode(CENTER)
            textMode(CORNER)
            fontSize(55)
            fill(0, 0, 0, 255)
            text("LEFT",9,10) 
            rectMode(CORNER)
            fill(0, 255, 251, 255)
            stroke(0, 0, 0, 255)
            rect(197,-3,200,100)
            rectMode(CENTER)
            textMode(CORNER)
            fontSize(55)
            fill(0, 0, 0, 255)
            text("RIGHT",209,10) 
            rectMode(CENTER)
                    rectMode(CORNER)
            fill(0, 255, 251, 255)
            stroke(0, 0, 0, 255)
            rect(95,97,200,100)
            rectMode(CENTER)
            textMode(CORNER)
            fontSize(55)
            fill(0, 0, 0, 255)
            text("RIGHT",209,10) 
            rectMode(CENTER)
    
            sprite("Documents:Cyborg",Player.x,Player.y,73,90)
    if Scene == 5 then
             rectMode(CENTER)
            stroke(0, 0, 0, 255)
            fill(127, 127, 127, 255)
            strokeWidth(5)
            fontSize(84)
            stroke(0, 0, 0, 255)
            background(35, 47, 47, 255)
            rectMode(CENTER)
            fill(0, 0, 0, 255)
             rect(floor1.x,200,1200,90)
            fontSize(49)
            fill(0,0,0,250)
            rectMode(CORNER)
            fill(0, 255, 251, 255)
            rect(-3,-3,200,100)
            rectMode(CENTER)
            textMode(CORNER)
            fontSize(55)
            fill(0, 0, 0, 255)
            text("LEFT",9,10) 
            rectMode(CORNER)
            fill(0, 255, 251, 255)
            stroke(0, 0, 0, 255)
            rect(197,-3,200,100)
            rectMode(CENTER)
            textMode(CORNER)
            fontSize(55)
            fill(0, 0, 0, 255)
            text("RIGHT",209,10) 
            rectMode(CENTER)
                    rectMode(CORNER)
            fill(0, 255, 251, 255)
            stroke(0, 0, 0, 255)
            rect(95,97,200,100)
            rectMode(CENTER)
            textMode(CORNER)
            fontSize(55)
            fill(0, 0, 0, 255)
            text("RIGHT",209,10) 
            rectMode(CENTER)
    
            sprite("Documents:Cyborg",Player.x,Player.y,20,1000)   
            rect(WIDTH/2,HEIGHT/2,500,400)
    end
    end
    end
    
    
    --Buttons 
    --DeathMatch button 
    function touched(touch) 
        if touch.state == ENDED and touch.x > WIDTH/2 - 125 and 
                touch.x < WIDTH /2 + 125 and touch.y < HEIGHT/2+63 and 
                touch.y > HEIGHT/2- 63 and Scene == 2 then
            Scene = 3
            sound(SOUND_BLIT, 16900)
            Player.x = 500
            Player.y = 500
        end 
        --Play button 
        if touch.state == ENDED and touch.x > WIDTH/2 - 125 and 
                touch.x < WIDTH /2 + 125 and touch.y < HEIGHT/2+63 and 
                touch.y > HEIGHT/2- 63 and Scene == 1 then
            Scene = 2
            sound(SOUND_BLIT, 16900)
        end
        --Metro stage button 
        if touch.state == ENDED and touch.x > WIDTH/2 - 125 and 
            touch.x < WIDTH /2 + 125 and touch.y < HEIGHT/2+63 and 
                touch.y > HEIGHT/2- 63 and Scene == 3 then
            Scene = 4
            sound(SOUND_BLIT, 16900)
            floor1.x = 500
            floor1.y = 100
        end
        --Back button (title screen) 
        if touch.state == ENDED and touch.x > 0 and touch.x < 100 and 
            touch.y < 100 and touch.y > 0 and Scene ~= 1 and Scene ~= 4 then
            Scene = Scene -1
            sound(SOUND_BLIT, 16900)
        end  
        --Ingame buttons
        --Left button
        if Scene == 4 then
            if touch.x > 0 and touch.x < 200 and 
            touch.y < 100 and touch.y > 0 then
                if touch.state == BEGAN or touch.state == MOVING then
                    xVel = -100
                  yVel = 0
                    updatePlayerVel()
                end
            elseif touch.state == ENDED then
                xVel = 0
    
                updatePlayerVel()
            end
            --Right button
            if touch.x > 200 and touch.x < 400 and 
            touch.y < 100 and touch.y > 0 then
                if touch.state == BEGAN or touch.state == MOVING then
                    xVel = 100
                    yVel = 0
    
                    updatePlayerVel()
                end
            elseif touch.state == ENDED then
                xVel = 0
                updatePlayerVel()
            end
            --Jump button
    
           if touch.x > 95 and touch.x < 295 and 
            touch.y < 200 and touch.y > 100 then
                if touch.state == BEGAN then
                    yVel = 300
    
    
                updatePlayerVel()
            end
        end
    end 
    end
    function updatePlayerVel() 
        Player.linearVelocity = vec2(xVel,yVel) 
        end
    
  • Posts: 1,976

    Only put the three ~ at the very top and very bottom of your code...

  • What three

  • edited August 2013 Posts: 1,976

    The ~~~. Put them at only the very top and very bottom of your code for proper code formatting.

  • There you go.

  • Posts: 1,976

    It doesn't draw any sprites for me, just black rectangles.

  • edited August 2013 Posts: 59

    Oh, that's because the sprite is my Dropbox file. Just change both sprites to one of your images and set the width to 73, the height to 90.

  • Posts: 1,976

    It's properly sized for me. If you have transparent pixels around the edges, it might render those, though, and appear as if it's smaller than it really is.

  • Yes, it's right for me too, but its like I set the height to 1000. But when I play the program the height is still 50 or something. Then I exit the program editor and come back in and it says the height is 50. Then when I change it, it works. Codea isn't saving properly.

  • Posts: 1,976

    1000 resizes it for me. Can you explain exactly what you did, and every button you pressed when it wasn't saving?

  • Well at first I uploaded an image of a robot. I tapped the sprite bubble and selected the robot. That worked fine. Later I tapped the sprite bubble and set it to an image of a blob. When I played the program, It still showed an image of a robot. I wrote this then went back into the editor to find that it still showed the image as Documents:Robot 2 (the robot file). I tapped it and selected the image of the blob. It drew the blob when I ran the program then. The blob was too big, so I set it to a smaller size. It seemed to be drawing the same size, but I wasn't sure. I then set the height to 1000, but it was exactly the same. But when I exited the editor and then readjusted the size, it resized properly.
    I seem to be in a bigger problem the just Codea not drawing the right image.

  • Posts: 38

    Are you using Aircode?

  • Posts: 157

    if he is, this is another problem I've seen with Aircode: taking a long time to update things, if it ever happens. More than once, I've edited a bunch of code, not seen the change in the draw loop, and refreshed the browser, only to find that the code in the project was still the old stuff.

    I would suggest working directly on the iPad, using a Bluetooth keyboard. AirCode just isn't ready for prime time quite yet, it would seem.

  • Posts: 25

    If you press the play button in the editor while the image picking screen is up, it won't select anything i think. It happens with the color picker as well.

  • I'm not using air code and the image screen isn't up.

Sign In or Register to comment.