[Help] [LÖVEPotion] How do I make it so that my character won't move past the screen?

Discussion in '3DS - Homebrew Development and Emulators' started by DutchyDutch, Aug 15, 2016.

  1. DutchyDutch
    OP

    DutchyDutch COPYRIGHT LOLOLOLOL

    Member
    869
    430
    Nov 16, 2014
    Netherlands
    Hi, yesterday I started developing in LovePotion for the 3DS. In about 20 hours I've already got the basics down... except for a few things. This glitch is one of them.

    The problem is this:
    I managed to make a top down game with a moving character and a scrolling background. When the dpad is pressed, the character moves up, and the BG moves down. This gives a scrolling BG effect. However, sometimes, my character moves past the screen, so you can't see him anymore. How do I fix this?

    Source code:
    Warning: Spoilers inside!


    If it's really necessary I could provide a short video of it pretty soon, just tell me.
    Thanks for reading this!
     
  2. c4388354

    c4388354 Advanced Member

    Newcomer
    90
    76
    Jan 23, 2015
    United States
    before adding the 1.1, do a check to see if the current x or y position is lower then a certain value (like 240) if it is then add the 1.1, if not then don't do anything.

    same when subtracting, make sure that the value is higher then a certain value (like 2), if it is then subtract the 1.1, if not then don't do anything.

    maybe try something like:
    Code:
    if love.keyboard.isDown("right") then
        if youngboyx < 240: youngboyx = youngboyx + 1.1
    end
    also, you can combine the "youngboyy = youngboyy + 1.1" and "backgroundy = backgroundy - 3.1" part into one if statement.

    example:
    before:
    Code:
    if love.keyboard.isDown("down") then
    youngboyy = youngboyy + 1.1
    end
    
    if love.keyboard.isDown("down") then
    backgroundy = backgroundy - 3.1
    end
    
    after:
    Code:
    if love.keyboard.isDown("down") then
        if youngboyx < 240:
            youngboyy = youngboyy + 1.1
            backgroundy = backgroundy - 3.1
    
    edit: fix codebox spacing
     
    Last edited by c4388354, Aug 15, 2016
  3. DutchyDutch
    OP

    DutchyDutch COPYRIGHT LOLOLOLOL

    Member
    869
    430
    Nov 16, 2014
    Netherlands
    That worked perfectly! :D Thanks!