Slick Forums
http://slick.ninjacave.com/forum/

camera questions
http://slick.ninjacave.com/forum/viewtopic.php?f=13&t=5903
Page 1 of 1

Author:  oblivion5683 [ Sun Nov 25, 2012 10:14 pm ]
Post subject:  camera questions

(sorry i make so many topics just have a lot of questions and this is my best place to find answers)

so i just restarted making my game again, and i want to upgrade the way the game is viewed, how would i go about having the screens view always centered on a moving sprite, befroe i just kept the sprite in the same place and moved the backround, but thats ridiculus.


EDIT: also how do you get keyboard input from a class outside a state useing the if(input.isKeyDown(Input.KEY_WHATEVERKEY)) method, because you dont have agame container variable, should i make a new one? how does that work?

Author:  TrentonZero [ Mon Nov 26, 2012 6:59 pm ]
Post subject:  Re: camera questions

Quote:
EDIT: also how do you get keyboard input from a class outside a state useing the if(input.isKeyDown(Input.KEY_WHATEVERKEY)) method, because you dont have agame container variable, should i make a new one? how does that work?


No, do not create a new one.

Instead, slick will send you the game container in update. You can in turn send that same game container object to any method tha tneeds its.

Code:
// this is written off the top of my head. look for the point not the literal syntax.

void update(GameContainer gc) {

    myObject.update(gc);
}

public class MyObject {


    public void update(GameContainer gc) {
          gc.getInput(); // or whatever. this is the exact same GC as in the above method. There is only one instance and you are passing it around.
    }
}

Author:  oblivion5683 [ Tue Nov 27, 2012 1:49 am ]
Post subject:  Re: camera questions

ok, thanks for replying
i actually ended up solving it by just using lwjgls method of input detection, much cleaner i think

Author:  oblivion5683 [ Wed Nov 28, 2012 12:32 am ]
Post subject:  Re: camera questions

still got the camera problem though, and thats kinda the bigger one
i dont know how to shift the screen

Author:  Liam [ Wed Nov 28, 2012 11:24 am ]
Post subject:  Re: camera questions

I think you may find this example to be particularly useful:

https://bitbucket.org/kevglass/slick/sr ... at=default

You can find the resources necessary to run this example here:

https://bitbucket.org/kevglass/slick/sr ... at=default

Author:  oblivion5683 [ Wed Nov 28, 2012 3:51 pm ]
Post subject:  Re: camera questions

hmmm, ok ill look at that

EDIT:ok i see now, im guessing that the scrolling is done by Graphics.Translate? how do i do that in another class without making a new graphics object? everytime i tyr it tells me i cant make a non static reference to a static object, but its not static.

Author:  Magn919 [ Wed Nov 28, 2012 4:38 pm ]
Post subject:  Re: camera questions

if you use Graphics.Translate() directly rather than the instance of Graphics that you get from slicks render method, you are calling it statically.
instead pass it to your own object via a parameter, just like TrentonZero explained you should do with the GameContainer object.

Author:  oblivion5683 [ Wed Nov 28, 2012 4:41 pm ]
Post subject:  Re: camera questions

hmmm, ok, i think i might get it, kinda confused still. ill try, sorry im so new to this and dont get things.




EDIT:i see the problem, renders graphics variable is being created in the render method, and so i cant use it outside of it, right?, maybe not

Author:  oblivion5683 [ Tue Dec 04, 2012 5:44 am ]
Post subject:  Re: camera questions

ok, this is kinda getting agravating, ive been lopking and looking and looking. heres my code:


Code:
package zelda;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import java.awt.Rectangle;
import org.newdawn.slick.Graphics;




public class TestLevel extends BasicGameState{

   Image image;
   boolean quit = false;
   Player link;
   Graphics s;

   
   public TestLevel(int state) throws SlickException {
   
   }
   
   
   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
      image = new Image("res/playNow.png");
      link = new Player();
   }
   
   
   public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
      
      g.drawString(" xpos = "+ link.Xpos + " Ypos = " + link.Ypos, link.Xpos, link.Ypos + 20);
      g.toString();
      g.drawString(g.toString(),50,50);
   }
   
   
   
   public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
   link.Start();
   Input input = gc.getInput();
      
      
      
      //start exit menu
      if(input.isKeyDown(Input.KEY_ESCAPE)){
         quit = true;
      }
         if(quit==true){
           
            if(input.isKeyDown(Input.KEY_R)){
               quit = false;

            }
            if(input.isKeyDown(Input.KEY_M)){
               sbg.enterState(0);
               try{
                  Thread.sleep(250);
               }catch(InterruptedException e){
                  e.printStackTrace();
               }
            }
            if(input.isKeyDown(Input.KEY_Q))
               System.exit(0);
            }
      
        
   }
   
   
   
   public int getID(){
      return 1;
   }
}



assume all the referenced classes exist
all i want to do i have the graphics object created for a parameter of the
render method, to be a refenerce instead of being created right there,
WHY cant i just do that, and if i can, why is it that nowhere i look tells me how?

Author:  joki [ Mon Dec 10, 2012 9:52 pm ]
Post subject:  Re: camera questions

Code:
   Image image;

Make a RessourceManager class, that handles access to the ressources, like animations, graphics, sounds.... for you.

Code:
      g.toString();

You are calling .toString on your Graphics ref without doing anything with it.

Code:
     g.drawString(" xpos = "+ link.Xpos + " Ypos = " + link.Ypos, link.Xpos, link.Ypos + 20);

rather call link.render(GameContainer gc, Graphics g) and have the Player class implement its own render() method, where you have it draw itself.

Code:
  link.Start();

Whats in here? :D

Code:
      if(input.isKeyDown(Input.KEY_ESCAPE)){
         quit = true;
      }
         if(quit==true){
                           }


Your keys are only polled, while holding down ESC. Not to mention, its not really _that_ usefull to assign a value to a variable, which only purpose is, to be evaluated in the next line.

Author:  oblivion5683 [ Wed Dec 12, 2012 5:20 pm ]
Post subject:  Re: camera questions

thanks for replying, as for all your comments:

i will make a resource manager, thanks i didnt know about that

the unused g.toString was just a lne i forgot to delete

link.start is the method that checks all the collisions for the character and things like that. i later changed it it link.Update

also the esc thing is just mt atempt at making a pause menu, which failed and also later got deleted

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/