![]() ![]() ScrollImage = new GreenfootImage(wide*world.getCellSize(), high*world.getCellSize()) create an image as large as scrolling area tiled, if needeed Public Scroller(World viewWorld, GreenfootImage image, int wide, int high) ![]() * the given value must be at least equal to the height of 'viewWorld' and * high the height of the visible area encompassed through scrolling * is given in world cells (not in pixels) ![]() * the given value must be at least equal to the width of 'viewWorld' and * wide the width of the visible area encompassed through scrolling * image the background image that will be tiled, if needed, to fill the scrolling area * If 'image' is null, the background will not change * If 'image' is smaller than the given total scrolling area, it will be tiled * This constructor is for a limited scrolling world Scroll(0, 0) // sets initial background image Public Scroller(World viewWorld, GreenfootImage image) * image the background image that will be tiled, if needed, and wrap with scrolling * viewWorld the world that scrolling will be performed on * If 'image' is null, the background will not change else the given image is wrapped * This constructor is for an unlimited scrolling world Private int wide, high // if limited, dimensions of scrolling area else of image to wrap Private int scrolledX, scrolledY // current scrolled distances Private boolean limited // flag to indicate whether scrolling is limited or not Private GreenfootImage scrollImage // scrolling image * It is the responsibility of the World object that creates a Scroller object to determine when * are removed from the world if no longer needed when out of view will help to prevent lag, ![]() * should be unbounded, allowing actors to move beyond the visible area. * size of the world that is visible) smaller can help in CPU expense, also. * image, the smaller that background image to be tiled, the better. For unlimited scrolling using a background * probably worse than having the background scroll). * it is better not to have a scrolling background image (having an Actor for the background is Because image manipulation can hog up CPU time, it is important to remember that * one for unlimited scrolling and one for limited scrolling. * DESCRIPTION: This is a support class for a scrolling world. Now we want to know how to add objects like a healthbar to the scrolling world so that they scroll too? We have implemented all your solutions and it works great. MyImage.fillRect(1, 1, health*pixelsPerHealthPoint, healthBarHeight ) MyImage.drawRect(0, 0, healthBarWidth +1, healthBarHeight + 1) SetImage(new GreenfootImage(healthBarWidth + 2, healthBarHeight + 2)) * the 'Act' or 'Run' button gets pressed in the environment. * Act - do whatever the HealthBar wants to do. Int pixelsPerHealthPoint = (int)healthBarWidth/health * Write a description of class Healthfor here. Hello,now we have a new problem, they are in all lines, where "scroller.scroll" is. Int signX=(int)Math.signum(dsx),signY=(int)Math.signum(dsy) If(scrollActor.getY()hiY)dsy=scrollActor.getY()-hiY If(scrollActor.getX()hiX)dsx=scrollActor.getX()-hiX If(Greenfoot.mouseClicked(this))scrollActor=null If(scrollActor!=null)scroll() else keyScroll() GreenfootImage image=new GreenfootImage("background") * Constructor for objects of class ActorScrollWorld. Public class OpenScrollWorld extends World Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) 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. So on this way I have a scrolling background - but it doesn´t work- there appear no objects. 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. 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.Īnd then the s: S = the value of x minus the value of f. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |