Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    if noone knows how to fix or why it does it, then anyone knows alternative how could i make tiles to listen mouseclicks?
  2. #17
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,024
    Rep Power
    1286
    Originally Posted by whijavanub
    if noone knows how to fix or why it does it, then anyone knows alternative how could i make tiles to listen mouseclicks?
    In what package are the Screen class and Pilt?
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by bullet
    In what package are the Screen class and Pilt?
    both is package 'graafika'
  6. #19
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,024
    Rep Power
    1286
    Originally Posted by whijavanub
    both is package 'graafika'
    Is this a publicly available package? We can't test your code without having the package.
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by bullet
    Is this a publicly available package? We can't test your code without having the package.
    Pilt class
    Code:
    package Graafika;
    
    
    public class Pilt {
    
    	public final int SIZE;
    	private int x, y;
    	public int[] pixels;
    	private PildiKogumid sheet;
    	
    	public static Pilt grass = new Pilt(16, 0, 0, PildiKogumid.tiles);
    	public static Pilt grass2 = new Pilt(16, 0, 1, PildiKogumid.tiles);
    	public static Pilt stone = new Pilt(16, 1, 0, PildiKogumid.tiles);
    	public static Pilt water = new Pilt(16, 2, 0, PildiKogumid.tiles);
    	public static Pilt voidSprite = new Pilt(16, 0xffffff);	
    		
    	public Pilt(int size, int x, int y, PildiKogumid sheet){
    		SIZE = size;
    		pixels = new int[SIZE*SIZE];
    		this.x = x*size;
    		this.y = y*size;
    		this.sheet = sheet;
    		load();
    	}
    	
    	public Pilt (int size, int colour){
    		SIZE = size;
    		pixels = new int[SIZE*SIZE];
    		setColour(colour);
    	}
    
    	private void setColour(int colour) {
    		for (int i=0; i<SIZE*SIZE; i++){
    			pixels[i] = colour;
    		}
    	}
    
    	private void load() {
    		for (int y=0; y<SIZE; y++){
    			for (int x=0; x<SIZE; x++){
    				pixels[x+y*SIZE] = sheet.pixels[(x+this.x)+(y+this.y)*sheet.SIZE];
    			}
    		}
    	}
    }
    i have lot of pictures but left in only few of them.

    Screen class
    Code:
    package Graafika;
    
    public class Screen {
    
    	public int width, height;
    	public int[] pixels;
    	public final int MAP_SIZE = 64;
    	public final int MAP_SIZE_MASK = MAP_SIZE - 1;
    
    	public int xOffset, yOffset;
    	
    	public int[] tiles = new int[MAP_SIZE*MAP_SIZE];
    
    	public Screen (int width, int height){
    		this.width = width;
    		this.height = height;
    		pixels = new int[width*height];	//54000
    	
    	}
    	
    	public void clear(){
    		for (int i=0; i<pixels.length; i++) {
    			pixels[i] = 0;}
    		
    	}
    
    	public void renderTile(int xOff, int yOff, Pilt pilt){
    		xOff -= xOffset; //invertib mapil liikumise
    		yOff -= yOffset; //invertib mapil liikumise
    		
    		for (int y=0; y<pilt.SIZE; y++){
    			int ya = y+yOff;
    			for (int x=0; x<pilt.SIZE; x++){
    				int xa = x+xOff;
    				if (xa<0-pilt.SIZE || xa >= width || ya<0 || ya>=height) continue;
    				if (xa<0) xa=0;
    				pixels[xa+ya*width] = pilt.pixels[x+y*pilt.SIZE];
    			}}
    	}
    	
    	public void renderClock(int xOff, int yOff, Pilt pilt){
    		xOff -= xOffset; //invertib mapil liikumise
    		yOff -= yOffset; //invertib mapil liikumise
    		
    		for (int y=0; y<32; y++){
    			int ya = y+yOff;
    			for (int x=0; x<32; x++){
    				int xa = x+xOff;
    				if (xa<0-32 || xa >= width || ya<0 || ya>=height) continue;
    				if (xa<0) xa=0;
    				int color = pilt.pixels[x+y*32];
    				if (color != 0xffff00ff) pixels[xa+ya*width] = color;
    			}}
    	}
    	
    	public void renderUnit(int xOff, int yOff, Pilt pilt){
    		xOff -= xOffset; //invertib mapil liikumise
    		yOff -= yOffset; //invertib mapil liikumise
    		
    		for (int y=0; y<pilt.SIZE; y++){
    			int ya = y+yOff;
    			for (int x=0; x<pilt.SIZE; x++){
    				int xa = x+xOff;
    				if (xa<0 - pilt.SIZE || xa >= width || ya<0 || ya>=height) break;
    				if (xa<0) xa=0;
    				int color = pilt.pixels[x+y*pilt.SIZE];
    				if (color != 0xffff00ff) pixels[xa+ya*width] = color;
    			}}
    	}
    	
    	public void setOffset (int xOffset, int yOffset){
    		this.xOffset = xOffset;
    		this.yOffset = yOffset;
    	}
    
    }
  10. #21
  11. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,024
    Rep Power
    1286
    Is there a complete package that can be downloaded? Pilt contains references to other classes. No one can compile the code without having all the classes.
  12. #22
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by bullet
    Is there a complete package that can be downloaded? Pilt contains references to other classes. No one can compile the code without having all the classes.
    well no, but why u need all that?
    My issue is with Mousehandler, everything else works fine.

    I figured if i do new Tile system all together i still may have the same problem.

    I still think the problem is because MouseHandler click is static.
    becaus when i use the same thing on any other object, it works fine.

    I wonder if i do new class what accept clicks and takes in the attributes from other classes.
  14. #23
  15. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,024
    Rep Power
    1286
    The problem is that no one can compile your code because it references files from that package. So we can't see what it does.
  16. #24
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by bullet
    The problem is that no one can compile your code because it references files from that package. So we can't see what it does.
    do you have a dropbox? or skype where i could send all the codes and pictures?
  18. #25
  19. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,024
    Rep Power
    1286
    Originally Posted by whijavanub
    do you have a dropbox? or skype where i could send all the codes and pictures?
    You can create a dropbox account and upload them there and then share the URL.
  20. #26
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by bullet
    You can create a dropbox account and upload them there and then share the URL.
    https://www.dropbox.com/sh/p5pgvaw1bfgbvef/yk6HHXbyOH

    hope its right
  22. #27
  23. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,024
    Rep Power
    1286
    Originally Posted by whijavanub
    https://www.dropbox.com/sh/p5pgvaw1bfgbvef/yk6HHXbyOH

    hope its right
    Ok I executed and ran your code and I get a screen where you have a figure drawn and at the top left there is a countdown. Is this right?
  24. #28
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by bullet
    Ok I executed and ran your code and I get a screen where you have a figure drawn and at the top left there is a countdown. Is this right?
    yup
  26. #29
  27. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,024
    Rep Power
    1286
    Originally Posted by whijavanub
    yup
    Ok. Can you point out where the issue is? I was able to click in the window and it printed coordinates.
  28. #30
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by bullet
    Ok. Can you point out where the issue is? I was able to click in the window and it printed coordinates.
    well, like i said in post 1, i want the clicked turn true when i click on GrassTile.
    Right now it either doesnt do anything.
    OR
    Gives only False.

    (well since it took forever to solve this particular problem, i though its impossible and i came to that problem from different angle and its kinda solved, but if there is way to fix it, i would like to know it)
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo