Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LWJGL rendering problem?  (Read 1239 times)
0 Members and 1 Guest are viewing this topic.
Offline PeterNicholson

Senior Member


Medals: 3
Projects: 1



« Posted 2012-08-28 15:33:22 »

Hello!
Can anybody help me? Ive got this problem. I have created a game, where you have to build shops. I have this code:
1  
2  
3  
if (Mouse.isButtonDown(0) {
            stall(mouseX, mouseY);
        }

And this code to set the value to the var, in the main game loop:
1  
2  
mouseX = Mouse.getX();
mouseY = Mouse.getY();

When I start the game, and I click the left mouse button, the shop appeares, but after I take my finger of the mouse
button, it disappeares! Please help!

my shop code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public static void stall(int x, int y) {
        glLoadIdentity();
        store.bind();
        glTranslatef(x, y, 0);
        glBegin(GL_QUADS);
            glTexCoord2f(0, 0);
            glVertex2f(0, 0);
            glTexCoord2f(0, store.getHeight());
            glVertex2f(0, 50);
            glTexCoord2f(store.getWidth(), store.getHeight());
            glVertex2f(50, 50);
            glTexCoord2f(store.getWidth(), 0);
            glVertex2f(50, 0);
        glEnd();

Subscribe to me on YouTube: http://youtube.com/javaprogrammerguy
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #1 - Posted 2012-08-28 15:48:31 »

I would recommend storing the last state of the left-button in a persistent variable somewhere.

1  
boolean lastLeftButtonState;


Then each frame while you are processing the input events, check to see if a state change (0 -> 1 or 1 -> 0) occurs.  This corresponds to a 'pressed' or 'released' event.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
boolean isLeftButtonDown = Mouse.isButtonDown(0);
if (isLeftButtonDown != lastLeftButtonState) {
  // a transition has occurred; determine what it is and trigger an event.
 if (isLeftButtonDown) {
    // pressed event; add your shop to the game state
 } else {
    // released event
 }
  lastLeftButtonState = isLeftButtonDown;
}


Then add handling to detect a 'pressed' event and add your shop.

Inside your render loop, check your game state for the shop and if it's present, display it.
Offline PeterNicholson

Senior Member


Medals: 3
Projects: 1



« Reply #2 - Posted 2012-08-28 15:55:43 »

Sorry, Id did not work Sad

Subscribe to me on YouTube: http://youtube.com/javaprogrammerguy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #3 - Posted 2012-08-28 15:59:10 »

You need to actually store the existence of your shop in a variable somewhere.  Then read that variable during the render pass.

Right now you're triggering the display of your shop based on the mouse button state.  The input event handling and render pass is occurring 60 times per second.
Offline theagentd
« Reply #4 - Posted 2012-08-28 16:10:35 »

What your code is currently doing is that it checks if the mouse button is pressed down and draws a stall if it is. Once you let it go it will disappear, because that's exactly what you've told it to do.

What you want to do is add your stall to a list, and draw all stalls in the list each frame. This will allow you add and remove stalls whenever you want to.

Myomyomyo.
Offline PixelDeBurner

Junior Member


Medals: 1



« Reply #5 - Posted 2012-08-29 10:16:58 »

I don't know, but maybe there is isMousePressed(int mb) method, that you should use ?
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #6 - Posted 2012-08-29 12:06:14 »

I'm going to go one step further and assume you don't fully understand Java and OOP. I recommend you learn both fully before jumping into a complex API like OpenGL.

Online matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #7 - Posted 2012-08-29 17:03:02 »

I have seen stuff you previously coded.

that stall(mouseX, mouseY) only renders the stall.

If you stop pressing the left mouse button, it stops to get inside the if statment, and with that doesn't render your stall Smiley

(A little hard without to know what stall actually does. I've seen it in another post of you Smiley )

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (14 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!