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

2013/5/19

Scrolling

1
2
Gzuzfrk Gzuzfrk

2013/5/19

#
Can someone please give me a simple scrolling screen code?
Gzuzfrk Gzuzfrk

2013/5/19

#
That scrolls by itself with the character running with it
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
int backgroundPosition = 0 int moveAmount = how many pixels you want it to move GreenfootImage yourBackgroundImage = your background image public void act() { backgroundPosition -= moveAmount; getWorld().getBackground().drawImage(yourBackgroundImage, backGroundPosition, 0); } can you do me a favor and go here http://www.greenfoot.org/scenarios/8396 and set a high score so i can make sure its working
Gzuzfrk Gzuzfrk

2013/5/19

#
Sure! But one question will that make it to where it looks like the character is running towards something while the screen is scrolling?
Gzuzfrk Gzuzfrk

2013/5/19

#
Oh sorry forgot I don't have Java so it doesn't play for me for some reason
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
that will scroll the screen let assume you've got the player running saved as 7 image named run 1-7 all .png format this would go in your player class int runNo = 0; String run = { "run1.png", "run2.png", "run3.png", "run4.png", "run5.png", "run6.png", "run7.png" }; public void act() { setImage(runR); runNo++; if(runNo > 6) { runNo = 0; } }
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
so the whole thing would be int runNo = 0; int backgroundPosition = 0 int moveAmount = how many pixels you want it to move GreenfootImage yourBackgroundImage = your background image String run = { "run1.png", "run2.png", "run3.png", "run4.png", "run5.png", "run6.png", "run7.png" }; public void act() { backgroundPosition -= moveAmount; getWorld().getBackground().drawImage(yourBackgroundImage, backGroundPosition, 0); setImage(runR); runNo++; if(runNo > 6) { runNo = 0; } } put that in your player class get the images for the player running remember for "if(runNo > 6) { runNo = 0; }" the 6 should be the number of images - 1
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
u don't have java
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
?
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
how much crack have u smoked today pal?
Gzuzfrk Gzuzfrk

2013/5/19

#
What is runR?
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
thats supposed to say run. it's a reference to String run = { "run1.png", "run2.png", "run3.png", "run4.png", "run5.png", "run6.png", "run7.png" }; if u want any more help with this need 2 download java and set a score on my game
Gzuzfrk Gzuzfrk

2013/5/19

#
Lol nah man I have a standalone on flash drive
Gzuzfrk Gzuzfrk

2013/5/19

#
int runNo = 0; int backgroundPosition = 0; int moveAmount = 5; GreenfootImage yourBackgroundImage = your background image; String run = { "Run1.png", "Run2.png", "Run3.png", "Run4.png", "Run5.png", "Run6.png"); public void act() { backgroundPosition -= moveAmount; getWorld().getBackground().drawImage(yourBackgroundImage, backGroundPosition, 0); setImage(runR); runNo++; if(runNo > 5) { runNo = 0; } } I have that in there but It's not working do replace yourBackground image with something?
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
lol having trouble getting it to work?
There are more replies on the next page.
1
2