vortieden.blogg.se

Scrolling world greenfoot source code
Scrolling world greenfoot source code







scrolling world greenfoot source code
  1. #Scrolling world greenfoot source code how to#
  2. #Scrolling world greenfoot source code code#

* 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.

#Scrolling world greenfoot source code how to#

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 Whatever the number (800, 600, 2), it is the number of possible returns, starting at zero and ending at one less than that number.Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) The 800 (which is the width of the world) and the 600 (which is the height of the world) ensure that what is returned will be somewhere in the world. (3) x and y, here, will be used to place a star in the world. The last statement will 'wrap' the star around the world: if on left edge, set the next x to at the right edge. That just makes each star move twice its speed.

#Scrolling world greenfoot source code code#

For some reason (or for no reason) this code is adding speed to the x location twice once in the 'x =.' statement and once in the 'setlocation(.' statement.

scrolling world greenfoot source code scrolling world greenfoot source code

(2) this is the part of the code that moves the star. The next line creates an image with that size and two lines later the circle (oval) drawn on the image also uses it as the diameter of the star. It is not really being used as a radius, but as a diameter here. Radius is actually the size of the star (in pixels).









Scrolling world greenfoot source code