riceleft.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#

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

scrolling world greenfoot source code

* 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 The original method was commented to make available if needed.Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

scrolling world greenfoot source code

One method of the scrolling support class has been slightly modified to scroll actors of this type properly. This demo uses my QActor superclass to give the main actor smooth movement and rotation. 'up', 'down', 'left', 'right': 8-way movement controls 'up', 'down', 'left', and 'right': 4-way movement controls Use 'enter' to switch between demo world and sample game world.

#SCROLLING WORLD GREENFOOT SOURCE CODE CODE#

The only limitation, which may be dealt with in a later update, is that the scrolling background image is obtained from the world background set at the time the direction of scrolling is set - however, this would complicate the code with more fields, checks and controls. Scrolls background with or without actor relocations Ĭapable of scrolling actors without scrolling the background image Ĭapable of limited scrolling as access to field values are provided through getter methods Scrolls either independent of any actor or by following an actor A support superclass for an infinite scrolling world Ĭapable of horizontal, vertical or universal scrolling










Scrolling world greenfoot source code