Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (593)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
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 1453 times)
0 Members and 1 Guest are viewing this topic.
Offline PeterNicholson

Senior Devvie

Medals: 3
Projects: 1

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

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

And this code to set the value to the var, in the main game loop:
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:

public static void stall(int x, int y) {
        glTranslatef(x, y, 0);
            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);

Subscribe to me on YouTube:
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.

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.

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 Devvie

Medals: 3
Projects: 1

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

Sorry, Id did not work Sad

Subscribe to me on YouTube:
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

« JGO Bitwise Duke »

Medals: 474
Projects: 2
Exp: 8 years

« 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.

Offline PixelDeBurner

Junior Devvie

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: 388
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.

Offline matheus23

JGO Kernel

Medals: 122
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.

deepthought (29 views)
2015-06-30 15:39:44

deepthought (31 views)
2015-06-30 15:39:09

deepthought (41 views)
2015-06-30 15:36:52

Za\'Anzabar (21 views)
2015-06-29 05:44:54

TritonDreyja (36 views)
2015-06-24 17:10:40

CopyableCougar4 (35 views)
2015-06-23 00:34:45

BurntPizza (39 views)
2015-06-21 20:36:46

cookiecompiler (81 views)
2015-06-11 15:42:53

cookiecompiler (45 views)
2015-06-11 15:41:14

NegativeZero (74 views)
2015-06-11 09:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 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‑
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!