Slick Forums

Discuss the Slick 2D Library
It is currently Mon Jun 18, 2018 7:40 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Apr 22, 2017 3:53 pm 
Offline

Joined: Sat Apr 22, 2017 3:40 pm
Posts: 4
Hello, I'm new to slick2D and fairly new to Java also. I've made a class called CreateGround which creates the img I'm going to use as the ground on my game. it's a 100x100 tilable picture, so am going to use many of them and set them besides each other. Which is why I think it would be better to have a class in itself that you could use to easily create ground blocks in different positions.

The class to create ground:
Code:
public class CreateGround extends Image {
    private static Image ground;
    private static float x,y;

    public void init(GameContainer gameContainer, StateBasedGame stateBasedGame) throws SlickException {
        ground = new Image("sprites/ground.png");
    }

    public void setPos(float x, float y) {
        this.x = x;
        this.y = y;
    }

    public void render(GameContainer gameContainer, Graphics graphics) throws SlickException {
        ground.draw(x,y);
    }
}


My problem is that I am not able to find out how I'm going to get it to draw the block on the main Game class. So far all I've tried have either made it crash, or not draw anything at all.

Main game file with only the relevant code that I've problems with, this is what I've tried so far:
Code:
public class Game extends BasicGameState {

CreateGround ground = new CreateGround();

    public void init(GameContainer gameContainer, StateBasedGame stateBasedGame) throws SlickException {
        ground.setPos(100,100);
    }

    public void render(GameContainer gameContainer, StateBasedGame stateBasedGame, Graphics graphics) throws SlickException {
   //ground.render(gameContainer, graphics);
        //ground.draw(100,100);
        //graphics.drawImage(ground, 100, 100);
    }
}


Top
 Profile  
 
PostPosted: Fri Apr 28, 2017 1:28 pm 
Offline

Joined: Sat Apr 22, 2017 3:40 pm
Posts: 4
We ended up just using simple shapes, collides work with it. And it's just simpler to do so for us, regarding the amount of time we have left to finish the project.


Top
 Profile  
 
PostPosted: Wed May 16, 2018 8:24 am 
Offline

Joined: Mon Apr 16, 2018 7:05 am
Posts: 1
How did it go?

_________________
Want to read about top online casino games and slots? It's so much fun reading about it right here. I read few reviews simultaneously. My mother is gonna play there soon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group