Results 1 to 5 of 5
  1. #1
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    124
    Rep Power
    0

    Default drawing function in a class

    I have 3 classes: particles, lightnign and energyball. I want to make it so, that at first there is the particles collectiong to single spot and and makeing a balal that grows bigger and bigger. Then when a certain size is achieved, it will change tha ball created by particles, to a ball that i draw in paint.Net and adds lightning to it(need to make target findindg code for it). ANd i want it all to be in a single render function in energyball class, that is called from the paint function from my board. How to i make that render function?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default Re: drawing function in a class

    You're going to have to take a step back and approach this problem one step at a time. What do you have working so far? Where are you stuck?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    124
    Rep Power
    0

    Default Re: drawing function in a class

    makeing that render function in energyball

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default Re: drawing function in a class

    I'd recommend posting your code in the form of an SSCCE, along with a specific technical question. There are several steps in the process you're trying to achieve, and it's hard to help you if you don't tell us exactly what you're stuck on.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    124
    Rep Power
    0

    Default Re: drawing function in a class

    Java Code:
    public class Energyball{
    	
    	private int x, y;
        private BufferedImage image;
        boolean visible;
    	boolean move;
    	boolean ready;
        private int width, height;
    	private BufferedImage[] frame = new BufferedImage[3];
    	
    	private int currentframe = 0;
    	private int sleep = 0;
    	private int[] sequence = {0,1,2};
    	private int[] attack= {1,2};
    	
        private final int MISSILE_SPEED = 2;
    	
    	public Energyball(int x, int y){
    		BufferedImage image = null;
    		try{
    			image = ImageIO.read(new File("C://Users//Marko//Desktop//java//lightning//Bossattack.png"));
    		} catch (IOException e) {
            }
    		for(int i = 0; i < 3; i = i+1){
    			frame[i] = image.getSubimage((i*16), 0,16,17);
    			}
            visible = true;
    		move = false;
    		ready = false;
            width = image.getWidth(null);
            height = image.getHeight(null);
            this.x = x;
            this.y = y;
        }
    
    
        public BufferedImage getImage() {
            return image;
        }
    
        public int getX() {
            return x;
        }
    
        public int getY() {
            return y;
        }
    	
    	public void setXY(int x, int y){
    		this.x = x;
    		this.y = y;
    		}
    
        public boolean isVisible() {
            return visible;
        }
    
        public void setVisible(Boolean visible) {
            this.visible = visible;
        }
    	
    	public void setMove(boolean move){
    		this.move = move;
    		}
    		
    	public boolean isMoveing(){
    		return move;
    		}
    
    	public BufferedImage getFrame(){
    		if(move){
    			if(sleep == 20){
    				sleep = 0;
    				return frame[attack[nextframe()]];
    				}
    			else{
    				sleep += 1;
    				return frame[attack[currentframe]];
    			}
    		}
    		
    		else if(ready){
    			if(sleep == 20){
    				sleep = 0;
    				return frame[attack[nextframe()]];
    				}
    			else{
    				sleep += 1;
    				return frame[attack[currentframe]];
    			}
    		}
    		
    		else{
    			if(sleep == 200){
    				sleep = 0;
    				return frame[sequence[nextframe()]];
    				}
    			else{
    				sleep += 1;
    				return frame[sequence[currentframe]];
    				}
    			}
    		}
    	
    
    	public BufferedImage getCurrentFrame(){
    		return frame[sequence[currentframe]];
    		}
    		
    	public int nextframe(){
    		if(move){
    			currentframe +=1;
    			if(currentframe >= attack.length){
    				currentframe = 0;
    				}
    			return currentframe;			
    		}
    		
    		else if(ready){
    			currentframe +=1;
    			if(currentframe >= attack.length){
    				currentframe = 0;
    				}
    			return currentframe;			
    		}
    		
    		else{
    			currentframe +=1;
    			if(currentframe >= sequence.length){
    				currentframe = 0;
    				ready = true;
    				}
    			return currentframe;
    			}
    		}
    		
        public Rectangle getBounds() {
            return new Rectangle(x, y, width/3, height);
        }
    
        public void move() {
    		if(move){
    			x -= MISSILE_SPEED;
    			if ((x+16) < 0){
    				visible = false;
    				}
    				}
        }
    }
    This is the energiball.java. In here i want to but a render function that draws everythign related tothe energy ball.
    Java Code:
    public void paint(Graphics g) {
            super.paint(g);
    		Graphics2D g2 = (Graphics2D) g;
            if (ingame) {	
    			g2.setColor(valk);
    			g2.setStroke(lai);
    			for(int i = 0; i < lightning.size(); i++){
    					g2.drawLine((int)lightning.get(i).getX1(), (int)lightning.get(i).getY1(), 
    						(int)lightning.get(i).getX2(), (int)lightning.get(i).getY2());
    				}
    			g2.drawImage(ball.getFrame(), ball.getX(), ball.getY(), this);
            } 
    
            Toolkit.getDefaultToolkit().sync();
            g2.dispose();
        }
    This is the paint funcion from my board.java. This is the function that should call out the render function from energyball.java

Similar Threads

  1. Replies: 3
    Last Post: 01-26-2012, 11:20 PM
  2. Replies: 0
    Last Post: 10-23-2011, 10:49 PM
  3. Drawing arbitary function applet
    By Dovla-- in forum Java Applets
    Replies: 0
    Last Post: 11-16-2010, 12:59 PM
  4. problem calling function from class to class
    By alin_ms in forum New To Java
    Replies: 3
    Last Post: 12-19-2008, 07:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •