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

2013/5/14

coins

Avik Avik

2013/5/14

#
PLEASE HELP ME> I NEED MY COINS TO MOVE WITH THE SCROLLING BACKGROUND. WHAT DO I DO!!!!!
Gevater_Tod4711 Gevater_Tod4711

2013/5/14

#
You need to move the coins the same size than the world. What kind of scrolling system do you use? If you can show us the code we might can help you doing that.
Avik Avik

2013/5/14

#
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A class that has a scrolling background image * * @author avik */ public class ScrollWorld extends World { private static final GreenfootImage bgImage = new GreenfootImage("Picture1.png"); private static final int scrollSpeed = 1; private GreenfootImage scrollingImage; private int scrollPosition = 0; public ScrollWorld() { super(800, 400, 1); GreenfootImage background = new GreenfootImage(800, 400); scrollingImage = getScrollingImage(800, 400); background.drawImage(scrollingImage, 0, 0); setBackground(background); addObject(new balloon(), 350, 200); } public void act() { if(scrollSpeed > 0 && scrollPosition <= 0) { scrollPosition = getWidth(); } if(scrollSpeed < 0 && scrollPosition >= getWidth()) { scrollPosition = 0; } 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; } }
Avik Avik

2013/5/16

#
this is the code
Gevater_Tod4711 Gevater_Tod4711

2013/5/16

#
The variable scrollSpeed is the movement of your background image if I got that right. So you have to move your coins the same distance.
Avik Avik

2013/5/16

#
could you post me the code for this
You need to login to post a reply.