This site requires JavaScript, please enable it in your browser!
Greenfoot back
Moritz
Moritz wrote ...

2012/5/26

scrolling background

Moritz Moritz

2012/5/26

#
Hey, I wanted to make a scrolling background. For that I have written to all sources of all objects they have to move to the right or left while pressing the "left or right" button. Only my character can not move sideways. It can only jump and fall - up and down arrow key. In the source code of the respective levels, I wrote:
 public void level(){
        
        if (Greenfoot.isKeyDown("right")){
            x++; (-> look for that below) 
        }
        if (Greenfoot.isKeyDown("left")) {
            f++; (-> look for that below)
        }
        
    }
    
    public void levelCreator1() {
        if (s==10) {  (look below what s means)
           addObject(new Object), 1200, 350);
           
        }
        if (s==25) {
            addObject(new Object2(), 1200, 350);
        }
        if (s==60) {
            addObject(new Object(), 1200, 350);
            addObject(new Object), 1200, 350);
        }
        
       
        
    }
I used x++; and f++; and s; At the top of the source code I wrote: private int s = x - f private int x = 0; private int f = 0; that means: if the right key is down the counter increases the variable x + 1; - the counter increases as long as the right button is pressed. the same with the left key and then the s: S = the value of x minus the value of f. So If you go press the right key so long that the value is 5 and you press the left key so long that the value is 5, too : S = 5 - 4 -> S=0 -> the character is on the same position... then I wrote for example: if (s==20) { addObject... } so on this way I have a scrolling background - but it doesn´t work- there appear no objects... when I only write s = 0; and I leave out the "left key" (f) it works - but then I can´t go to the left because then the objects appears not on the correct position ... can sb. help me?
Moritz Moritz

2012/5/26

#
Moritz wrote...
Hey, I wanted to make a scrolling background. For that I have written to all sources of all objects they have to move to the right or left while pressing the "left or right" button. Only my character can not move sideways. It can only jump and fall - up and down arrow key. In the source code of the respective levels, I wrote:
 public void level(){
        
        if (Greenfoot.isKeyDown("right")){
            x++; }
(-> look for that below)
        }

        if (Greenfoot.isKeyDown("left")) {
            f++; 
(-> look for that below)
        }
        
    }
    
    public void levelCreator1() {
        if (s==10) {  }
(look below what s means)
           addObject(new Object), 1200, 350);
           
        }
        if (s==25) {
            addObject(new Object2(), 1200, 350);
        }
        if (s==60) {
            addObject(new Object(), 1200, 350);
            addObject(new Object), 1200, 350);
        }
        
       
        
    }
I used x++; and f++; and s; At the top of the source code I wrote: private int s = x - f private int x = 0; private int f = 0; that means: if the right key is down the counter increases the variable x + 1; - the counter increases as long as the right button is pressed. the same with the left key and then the s: S = the value of x minus the value of f. So If you go press the right key so long that the value is 5 and you press the left key so long that the value is 5, too : S = 5 - 4 -> S=0 -> the character is on the same position... then I wrote for example: if (s==20) { addObject... } so on this way I have a scrolling background - but it doesn´t work- there appear no objects... when I only write s = 0; and I leave out the "left key" (f) it works - but then I can´t go to the left because then the objects appears not on the correct position ... can sb. help me?
Moritz Moritz

2012/5/26

#
Moritz wrote...
Moritz wrote...
Hey, I wanted to make a scrolling background. For that I have written to all sources of all objects they have to move to the right or left while pressing the "left or right" button. Only my character can not move sideways. It can only jump and fall - up and down arrow key. In the source code of the respective levels, I wrote:
 public void level(){
        
        if (Greenfoot.isKeyDown("right")){
            x++; }
(-> look for that below)
        }

        if (Greenfoot.isKeyDown("left")) {
            f++; 
(-> look for that below)
        }
        
    }
    
    public void levelCreator1() {
        if (s==10) {  }
(look below what s means)
           addObject(new Object), 1200, 350);
           
        }
        if (s==25) {
            addObject(new Object2(), 1200, 350);
        }
        if (s==60) {
            addObject(new Object(), 1200, 350);
            addObject(new Object), 1200, 350);
        }
        
       
        
    }
I used x++; and f++; and s; At the top of the source code I wrote: private int s = x - f private int x = 0; private int f = 0; that means: if the right key is down the counter increases the variable x + 1; - the counter increases as long as the right button is pressed. the same with the left key and then the s: S = the value of x minus the value of f. So If you go press the right key so long that the value is 5 and you press the left key so long that the value is 5, too : S = 5 - 4 -> S=0 -> the character is on the same position... then I wrote for example: if (s==20) { addObject... } so on this way I have a scrolling background - but it doesn´t work- there appear no objects... when I only write s = 0; and I leave out the "left key" (f) it works - but then I can´t go to the left because then the objects appears not on the correct position ... can sb. help me?
Moritz Moritz

2012/5/26

#
sorry for that... I don´t know how to delate that... and I mean s = 5-5 not 5-4
You need to login to post a reply.