Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 10:51 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: drawing during update
PostPosted: Mon Apr 30, 2012 5:29 pm 
Offline

Joined: Tue Apr 24, 2012 3:06 pm
Posts: 7
can I draw an image in the update method?


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 5:52 pm 
Offline
Regular

Joined: Sun Oct 25, 2009 5:24 pm
Posts: 118
It's not recommended. Draw stuff in render() and update the position in update().


Top
 Profile  
 
PostPosted: Tue May 01, 2012 11:56 am 
Offline

Joined: Tue Apr 24, 2012 3:06 pm
Posts: 7
ok, but it won't draw itself... =\ i need it to draw on a input from the mouse at a location


Top
 Profile  
 
PostPosted: Wed May 02, 2012 6:07 am 
Offline
Regular
User avatar

Joined: Wed Apr 27, 2011 3:29 pm
Posts: 194
Location: United State of California
I suppose storing the position of the mouse in a couple variables and boolean value representing whether or not the mouse button was pressed since the last update would do the job.

_________________
Current Testing Machine:
Windows 7 x64, 4GB RAM DDR3, 3.3ghz AMD Athlon II X3 455, AMD Radeon HD 6800 series.


Top
 Profile  
 
PostPosted: Wed May 02, 2012 7:09 pm 
Offline

Joined: Tue Apr 24, 2012 3:06 pm
Posts: 7
Biki wrote:
It's not recommended. Draw stuff in render() and update the position in update().

how to update its position? :S
EDIT:
Can someone please check this code and see what am I doing wrong?
Code:
   public void update(GameContainer arg0, StateBasedGame arg1, int arg2)
         throws SlickException {
      try {
         Thread.sleep(15);
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
      Input in = arg0.getInput();
      int x = in.getMouseX();
      int y = in.getMouseY();
      boolean c1 = false, c2 = false, c3 = false, c4 = false, c5 = false, c6 = false, c7 = false, c8 = false, c9 = false;
      if ((x >= 20 && x <= 149) && (y >= 20 && y <= 134)) {
         c1 = true;
      } else if ((x >= 172 && x <= 390) && (y >= 30 && y <= 132)) {
         c2 = true;
      } else if ((x >= 413 && x <= 545) && (y >= 43 && y <= 131)) {
         c3 = true;
      } else if ((x >= 19 && x <= 142) && (y >= 155 && y <= 430)) {
         c4 = true;
      } else if ((x >= 166 && x <= 373) && (y >= 155 && y <= 433)) {
         c5 = true;
      } else if ((x >= 409 && x <= 549) && (y >= 152 && y <= 437)) {
         c6 = true;
      } else if ((x >= 16 && x <= 140) && (y >= 451 && y <= 576)) {
         c7 = true;
      } else if ((x >= 163 && x <= 381) && (y >= 456 && y <= 580)) {
         c8 = true;
      } else if ((x >= 403 && x <= 529) && (y >= 460 && y <= 576)) {
         System.out.println("1");
         c9 = true;
         System.out.println("2");
      }

      if (c1) {
         grid = new GridCube(1);
         if ((!grid.isSomethingIn(1)) && (!grid.isComsTurn())) {
            if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
               X.draw(20, 20);
            }
         }
      }

      if (c2) {
         grid = new GridCube(2);
         if ((!grid.isSomethingIn(1)) && (!grid.isComsTurn())) {
            if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
               X.draw(172, 30);
            }
         }
      }
      if (c3) {
         grid = new GridCube(3);
         if ((!grid.isSomethingIn(3)) && (!grid.isComsTurn())) {
            if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
               X.draw(413, 43);
            }
         }
      }
      if (c4) {
         grid = new GridCube(4);
         if ((!grid.isSomethingIn(4)) && (!grid.isComsTurn())) {
            if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
               X.draw(19, 155);
            }
         }
      }
      if (c5) {
         grid = new GridCube(5);
         if ((!grid.isSomethingIn(5)) && (!grid.isComsTurn())) {
            if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
               X.draw(166, 155);
            }
         }
      }
      if (c6) {
         grid = new GridCube(6);
         if ((!grid.isSomethingIn(6)) && (!grid.isComsTurn())) {
            if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
               X.draw(409, 152);
            }
         }
      }
      if (c7) {
         grid = new GridCube(7);
         if ((!grid.isSomethingIn(7)) && (!grid.isComsTurn())) {
            if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
               X.draw(16, 451);
            }
         }
      }
      if (c8) {
         grid = new GridCube(8);
         if ((!grid.isSomethingIn(8)) && (!grid.isComsTurn())) {
            if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
               X.draw(163, 456);
            }
         }
      }
      if (c9) {
         System.out.println("3");
         grid = new GridCube(9);
         System.out.println("4");
         X.setAlpha(1);
      }
   }


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 0 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:  
Powered by phpBB® Forum Software © phpBB Group