Re: Can't Get Sprite To Stay In Screen Bounds

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...

Should be something like this:

if slGetKey(SL_KEY_LEFT) = 1 then 
    x -= 2 
    if x < 0 then 
        x = 0 
    end if 
    slSprite(spr,x,y,32,32) 
end if 

See if this works:

while not slShouldClose() do  
 
    slSetBackColor(255,255,255) --change background to white  
 
    if slGetKey(SL_KEY_ESCAPE) = 1 then  
        slClose()  
    end if  
 
    if slGetKey(SL_KEY_LEFT) = 1 then  
        x -= 2  
        if x < 0 then 
            x = 0 
        end if 
    end if  
 
    if slGetKey(SL_KEY_RIGHT) = 1 then  
        x += 2  
        if x > (WIDTH-32) then 
            x = WIDTH-32 
        end if 
    end if  
 
    slSprite(spr,x,y,32,32)  
 
    slRender()  
 
end while  

Thanks, it worked!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu