Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Simplifying fractions  (Read 5025 times)
0 Members and 1 Guest are viewing this topic.
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #30 - Posted 2009-03-01 14:51:00 »

ahh that explains a lot. I already hav eosmeting that works now. Iwill try ot use that now.

waht I realized was that I was casting my vx/100 as an int. wich cut of the decimal making it inacurate.

and since Hansdampf told me to change my x and y. It is now a decimal, and it keeps all of  its accuracy, and moves at a regular rate.

thanks all for your help.
Offline ewjordan

Junior Devvie





« Reply #31 - Posted 2009-03-02 01:48:34 »

Re: the static variable thing, the point people are trying to make is that while yes, static variables are the closest thing to global variables you can get in Java, you generally want as few global variables as possible in a project.  This cuts across language boundaries, and is good practice almost all the time.  Generally speaking, the only statics in an ideal design would be global constants that are absolutely never going to change, or singletons (which should be used sparingly at most), which are objects that both need a global access point and there can absolutely only be one of (whether singletons are ever necessary or acceptable to use is a hotly debated topic, one which hopefully we won't re-ignite here...).

Your example of making the player variables static is a good case to think about, because while it may work for now, suppose you eventually want to make a sequel to your game, and you want it to be multi-player, or you want competing AI units.  This will be much easier if your player is a full fledged object, in which case adding another player is just a matter of instantiating another object rather than duplicating each of the life/score/ammo/etc. fields (depending on the game) as global variables.

Also, if you're writing games that will ever run in a browser, statics are a serious problem.  Sometimes (the rules are seemingly random, though Sun will tell you there is some logic to it) they don't get reset if you leave a page and come back or reload, which means that your player's shield/score values will be the same as they were the last time the game was played, but only sometimes, and this is almost never the behavior you want.  There are workarounds, but it's better to design around the issue in the first place.

In summary, as Riven said, static variables are a recipe for pain, and you should feel dirty every time you use one, doubly so if it's not also final.  Of course there are exceptions to the rule, but it takes a lot of experience to know when it is safe and when it's not, so it's best to get into the habit of avoiding them initially until you know for sure when you're in one of the situations where they actually help.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #32 - Posted 2009-03-02 07:04:54 »

Just to add to that: for constants we've always had interface fields, and enums were added 'recently'.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #33 - Posted 2009-03-02 12:31:16 »

ok thank you for the clarification. I  may have to change some of the design inmy program. cause right now the shields are int he main game state. If I move it to the player class....

althouhg there is a problem with it though cause it will re-init it when the next level comes.

hey coulde some1 tell me how much the init()'s do, cause there are more than one.

cause I cannot find out what each does, and the discription in the class description is not very detailed.
Offline cylab

JGO Ninja


Medals: 55



« Reply #34 - Posted 2009-03-02 12:50:26 »

What init()'s ?

Normally you make your player a member of your game class' instance, so it doesn't change and you can lookup the right instance from elsewhere. But I mean a normal member, not a static one Wink Just pass around the objects as needed.

Mathias - I Know What [you] Did Last Summer!
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #35 - Posted 2009-03-02 12:54:40 »

sorry I may not have specified this, I am using Slick.
Offline cylab

JGO Ninja


Medals: 55



« Reply #36 - Posted 2009-03-02 13:13:15 »

Which class? What circumstances? How do you use it? Link to the javadoc you find not detailed enough?

Bottomline:
Make it easy to help you and don't make us feel like we being your mom and dad to breast feed you...
You know, most of us work for our living, so we have limited time Shocked

Mathias - I Know What [you] Did Last Summer!
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #37 - Posted 2009-03-02 14:23:12 »

wow this thread is very hostile.

the context: in a state, there are many init().

the link: I cant post now, I am at school Sad. why is cokeandecode blocked and java-gaming.org isnt....
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #38 - Posted 2009-03-02 14:28:25 »

Hm.. hostile? I think this is one of the most generous programmers forums on the planet (and far beyond).

I'd like to comment on 'mom and dad breast feeding', but I guess that would be a bit too offtopic.


H3ckboy, really, we've been giving you so much advice that our fingers hurt. You don't seem to work on your basic understanding on your Java knowlegde, which unfortunately, at this stage, is NOT aquired most by trial-and-error. You really have to study, or you'll waste (at least) your own time.

I'm not being harsh (or at least I'm not trying to be). Please take this advise seriously, and read good Java book, cover to cover, don't miss a word. You'll be glad you did.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #39 - Posted 2009-03-02 19:45:53 »

Quote
this thread

Yes this FORUM is a very awesome forum, did I say ti wasnt? no I said this thread.

and I am not whining.

oh yeah and jsut so you know everything I have learned has been throuhg trial and I dont think I am exagerating.

This thread has long lived beyond its original purpose and is going VERY off topic. so I am gunna stop posting in it.

cya all
Pages: 1 [2]
  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.

toopeicgaming1999 (65 views)
2014-11-26 15:22:04

toopeicgaming1999 (58 views)
2014-11-26 15:20:36

toopeicgaming1999 (10 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (28 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!