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

2014/3/27

How do I make vertical sidescroller from a normal sidescroller

nc-munk nc-munk

2014/3/27

#
This is my code so far import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) public class ScrollWorld extends World { private static final GreenfootImage bgImage = new GreenfootImage("space1.gif"); private static final int scrollSpeed = 1; private GreenfootImage scrollingImage; private int scrollPosition = 0; public ScrollWorld() { super(400, 600, 1); GreenfootImage background = new GreenfootImage(400, 600); scrollingImage = getScrollingImage(400, 600); background.drawImage(scrollingImage, 0, 0); setBackground(background); addObject(new SpaceShip(), 200, 575); } public void act() { if(scrollSpeed > 0 && scrollPosition <= 0) { scrollPosition = getWidth(); } if(scrollSpeed < 0 && scrollPosition >= getWidth()) { scrollPosition = 1; } scrollPosition -= scrollSpeed; paint(scrollPosition); } /** * Paint scrolling image at given position and make sure the rest of * the background is also painted with the same image. */ private void paint(int position) { GreenfootImage bg = getBackground(); bg.drawImage(scrollingImage, position, 0); bg.drawImage(scrollingImage, position - scrollingImage.getWidth(), 0); } /** * Returns an image with the given dimensions. */ private GreenfootImage getScrollingImage(int width, int height) { GreenfootImage image = new GreenfootImage(width, height); for(int x = 0; x < width; x += bgImage.getWidth()) { for(int y = 0; y < height; y += bgImage.getHeight()) { image.drawImage(bgImage, x, y); } } return image; } } It is bast on a sidescroller demo I want to make the bagground move vertical to the bottom of the screen sorry for poor english
danpost danpost

2014/3/27

#
Basically, change a few 'Width's to 'Height's and switch the arguments in the 'drawImage' lines.
nc-munk nc-munk

2014/3/28

#
What should the arguments be changed to
danpost danpost

2014/3/28

#
Instead of '(position, 0)' use '(0, position)' and similar with the other drawImage arguments.
You need to login to post a reply.