Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 18, 2013 3:46 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Jun 23, 2012 10:55 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
Hello, I wanted to test some simple stuff, and ran into problem.

I have MouseX and MouseY variables that get Mouse x position and y position ( obviously ), and when mouse clicked ( input.isMousePressed(0) ) , I want to draw rectangle, starting from mouse x and y position. But I want that rectangle to stay there, until I clear the screen, but it just blinks.

Can someone please help ?!


Top
 Profile  
 
PostPosted: Sun Jun 24, 2012 9:29 am 
Offline

Joined: Sat Jun 02, 2012 7:41 am
Posts: 67
You could create a class (e.g. Shape) that contains a couple of coordinates and draws the shape at that coordinates, then when you click the mouse button you instantiate a new object of that class with the current mouse coordinates, and add it to a list (such as ArrayList) of shapes. Then when you want to clear the screen you simply remove all the shape objects from the list.

Don't know if it's the best way to do this thogugh :?:


Top
 Profile  
 
PostPosted: Sun Jun 24, 2012 5:02 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1466
Yup, Alessandro is right.

Code:
List<Rectangle> rects = new ArrayList<Rectangle>();

...
    mousePressed(int b, int x, int y) {
        rects.add(new Rectangle(x, y, WIDTH, HEIGHT));
    }

...
   render... {
        for (Rectangle r : rects)
            g.fill(r);
    }


Top
 Profile  
 
PostPosted: Tue Jun 26, 2012 10:08 am 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
You Guys are amazing, it works just fine !

Thank you so much !


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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