Our project contains a sprite sheet slicer ( http://www.greenfoot.org/scenarios/8502 ) shared by Game/Maniac. I completed a test world using the sprite sheet slicer last night, and it works perfectly in Greenfoot, and as a jar application. Where it fails, is once we upload to Greenfoot site which is a requirement of the project. After uploading, the scenario fails to initialize. No errors, simply a black screen showing initializing.
Removing the Spritesheet class and all sub classes/spawned objects allows the scenario to load on the Greenfoot site. Any idea looking at this class and one sample subclass what might be causing this scenario to fail initialization?
This is the world working in the Greenfoot app.
https://i.gyazo.com/2161c6897e2e41993ea3f31e3533ca14.jpg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class SpriteSheet here. * * @author (Game/Maniac) * @version (2013/5/26) http://www.greenfoot.org/scenarios/8502 */ public class SpriteSheet extends Actor { /** * The if you switch your inputs for topLeftX, and bottomRightX the image will be flipped horizontilly, * if you do the same with the topLeftY and bottomRightY the image will be flipped vertically. The width * and height are the dimesions of the returned image. */ public GreenfootImage getSprite(GreenfootImage spriteSheet, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY, int width, int height) { int tempWidth; int tempHeight; if (topLeftX<bottomRightX) tempWidth = bottomRightX - topLeftX; else tempWidth = topLeftX - bottomRightX; if (topLeftY<bottomRightY) tempHeight = bottomRightY - topLeftY; else tempHeight = topLeftY - bottomRightY; GreenfootImage img = new GreenfootImage(tempWidth, tempHeight); if (topLeftX<bottomRightX) { for ( int x = topLeftX; x < bottomRightX; x++) { if (topLeftY<bottomRightY) { for ( int y = topLeftY; y < bottomRightY; y++) { if (x>= 0 && x<spriteSheet.getWidth() && y>= 0 && y<spriteSheet.getHeight()) { img.setColorAt(tempWidth-(bottomRightX - x), tempHeight-(bottomRightY - y), spriteSheet.getColorAt(x, y)); } } } else { for ( int y = bottomRightY; y < topLeftY; y++) { img.setColorAt(tempWidth-(bottomRightX - x), tempHeight-(topLeftY - y), spriteSheet.getColorAt(x, y)); } } } } else { for ( int x = bottomRightX; x < topLeftX; x++) { if (topLeftY<bottomRightY) { for ( int y = topLeftY; y < bottomRightY; y++) { img.setColorAt(tempWidth-(topLeftX - x), tempHeight-(bottomRightY - y), spriteSheet.getColorAt(x, y)); } } else { for ( int y = bottomRightY; y < topLeftY; y++) { img.setColorAt(tempWidth-(topLeftX - x), tempHeight-(topLeftY - y), spriteSheet.getColorAt(x, y)); } } } } img.scale(width, height); return img; } /** * This will return an object intersecting with the coloured part of your image. */ public Actor getAnIntersectingObject(Class clss) { GreenfootImage img = getImage(); Actor actor = null ; for ( int x = 0 ; x<img.getWidth(); x++) { for ( int y = 0 ; y<img.getHeight(); y++) { if (img.getColorAt(x, y).getAlpha()> 0 ) { if (getOneObjectAtOffset(x-img.getWidth()/ 2 , y-img.getHeight()/ 2 , clss)!= null ) { actor = getOneObjectAtOffset(x-img.getWidth()/ 2 , y-img.getHeight()/ 2 , clss); } } } } return actor; } /** * This uses an ID where 0 will be the first image on the sheet. The spriteCellWidth and Height are * the dimesions of each individual cells on your sprite sheet. The width and height are the dimesions * of the returned image. */ public GreenfootImage getSprite(GreenfootImage spriteSheet, int ID, int spriteCellWidth, int spriteCellHeight, int width, int height) { int topX = 0 ; int topY = 0 ; int rowSize = spriteSheet.getWidth()/spriteCellWidth; topX = (ID%rowSize)*spriteCellWidth; topY = (ID-(ID%rowSize))/rowSize*spriteCellHeight; return getSprite(spriteSheet, topX, topY, topX+spriteCellWidth, topY+spriteCellHeight, width, height); } /** * This uses an ID where 0 will be the first image on the sheet. The spriteCellWidth and Height are * the dimesions of each individual cells on your sprite sheet. */ public GreenfootImage getSprite(GreenfootImage spriteSheet, int ID, int spriteCellWidth, int spriteCellHeight) { return getSprite(spriteSheet, ID, spriteCellWidth, spriteCellHeight, spriteCellWidth, spriteCellHeight); } /** * This uses an ID where 0 will be the first image on the sheet. * The block width is the width of a SQUARE block on the sheet, * the returned image will also be a SQUARE block. */ public GreenfootImage getSprite(GreenfootImage spriteSheet, int ID, int blockWidth) { return getSprite(spriteSheet, ID, spriteSheet.getWidth()/blockWidth, spriteSheet.getHeight()/blockWidth); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * This is the grassland sprite sheet constructor class. Class breaks the grassland * sprite into a 16x16 grid that can be called from to create new actors. These * actors are used to create the world. * * @author (Benjamin Presley) * @version (04/26/2018) */ public class Grassland extends SpriteSheet { public int x1[] = { 1 , 64 , 128 , 192 , 256 , 320 , 384 , 448 , 512 , 576 , 640 , 704 , 768 , 832 , 896 , 960 }; public int y1[] = { 1 , 64 , 128 , 192 , 256 , 320 , 384 , 448 , 512 , 576 , 640 , 704 , 768 , 832 , 896 , 960 }; /** * Creates a grassland sprites. X and Y parameters are the grid coordinates from the sprite sheet. * x1 and y1 are the coordinates for the top left corner of requested grid square. Adding 60 gives * us our bottom right coordinates. This designates the area of the sprite sheet to display. */ public Grassland( int x, int y) { setImage(getSprite( new GreenfootImage( "Grassland.png" ), x1[x], y1[y], x1[x]+ 64 , y1[y]+ 64 , 64 , 64 )); } /** * This is the same as the above method, but adds a rotation parameter to allow for rotation of sprites. */ public Grassland( int x, int y, int r) { setImage(getSprite( new GreenfootImage( "Grassland.png" ), x1[x], y1[y], x1[x]+ 64 , y1[y]+ 64 , 64 , 64 )); this .setRotation(r); } } |