• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Arch@on

[java] Embarrassing question about my own code...

15 posts in this topic

I have filtered my code many hours, but I can''t find the problem, This one is really basic so I hope you can find error what I can''t: This one is from engineController object, this is just simple test, because after I messed my code just before taking backups, I tried to make it very simple to find error.. ...snip... part of engineController class EngineCanvas extends Canvas { Image Background; public void paint(Graphics g) { Tausta = getToolkit().getImage("dildo2.gif"); MediaTracker mt = new MediaTracker (this); mt.addImage (Background, 0); try { mt.waitForAll(); System.out.println("Image is loaded"); } catch (Exception e) { e.printStackTrace(); } g.drawImage(Background, 0, 0, this); } } heheh dildo2.gif is picture from my PC, I named it dildo because it looked... I''m not going to continue I''m calling engine canvas in my main object which tests the game. Here is how i load my canvas Canvas GoDView = new EngineCanvas(); It lies in borderlayout center, Jim told me that I should use setSize/setBounds, tried with it, negative
0

Share this post


Link to post
Share on other sites
I''m not sure this is it, and I''m not a c++ person (i like C), but make the "public void paint(Graphics g) {" line into this:
public:
void paint(Graphics g) {
I''m not sure if that''ll fix it, but try
0

Share this post


Link to post
Share on other sites
Hehe, it''d help if I''d realized that was a java forum... anyway, try it, it might work
0

Share this post


Link to post
Share on other sites
>>Tausta = getToolkit().getImage("dildo2.gif");


I hope you meant Background instead of Tausta, because I didn''t see "Tausta" anywhere else in the snippet.

JoeG
0

Share this post


Link to post
Share on other sites
I tried your code and got it working by setting the ImageObserver to null in the paint method. The problem seemed to be that the Component''s (the baseclass of Canvas) imageUpdate() method is trying to repaint the screen when new info about the image appers, but upon repaint you try to load a new image. And when that image is being loaded you get a repaint and when you get a repaint you start to load a new image and... Well you get the point

It''s not exactly a infinite loop as the repaint is scheduled by the repaint/event dispatch thread, thus there are some breaks in the loop that allow it to end. The image drawing just fails for some reason.

The practice of loading images in the paint() method is really not a recommended way to do image loading. At least doing it the way you''ve done it creates one image and one MediaTracker object per repaint. But since the code was only example code to make a point, I''ll forgive you
0

Share this post


Link to post
Share on other sites
That Tausta thing was that I translated Tausta to english background
And I''m drawing that in there, because I tried to make my code so simple that first-timer can get it working...
0

Share this post


Link to post
Share on other sites
Just wanted to say: put the image drawing thing into ''repaint'' - this way you should be able to avoid the ''loop''.
0

Share this post


Link to post
Share on other sites
I can''t get this work, it''s in repaint...I just can''t realize what I messed up, before this it painted all images, I wonder what I can do anymore? Can anyone of you tell me other way to draw images?
Btw javanerd you mentioned something about right way to load images? I''m loading my images in separate object called imageController (I got this cool style to name images from JGDC), I just draw them in paint, but before that they''ll have some fun with maploader... Njha, I won''t even try it today, I just play games and stuff, yeah...
0

Share this post


Link to post
Share on other sites
Well I''m going out on a limb here and I could be totally off (which wouldn''t surprise me) but you have:
Canvas GoDView = new EngineCanvas();
shouldn''t it be:
EngineCanvas GoDView = new EngineCanvas();

just outta curiosity?

-- From someone who can''t find his left from his other left.
0

Share this post


Link to post
Share on other sites
Well I''m going out on a limb here and I could be totally off (which wouldn''t surprise me) but you have:
Canvas GoDView = new EngineCanvas();
shouldn''t it be:
EngineCanvas GoDView = new EngineCanvas();
---

Both works, I don''t know which is right way...
0

Share this post


Link to post
Share on other sites
Canvas GoDView = new EngineCanvas();
vs.
EngineCanvas GoDView = new EngineCanvas();
----
There is no "right way" for this - it depends on what you need. If you want to transparently use an EngineCanvas in place of Canvas then the first way will do just fine. The second way is useful if you know you need to talk to an instance of EngineCanvas - so you can call Engine Canvas specific methods that aren''t found on Canvas.
0

Share this post


Link to post
Share on other sites
Moving the painting to repaint() doesn''t change anything as the repaint() actually invokes paint() after clearing the background...

Just change the line reading:
g.drawImage( Background, 0, 0, this );
to
g.drawImage( Background, 0, 0, null );

in the example and it works. At least in the example you don''t need the ImageObserver. Also in your original code you don''t seem to need it if you are handling the loading in different place anyhow and make sure the images are loaded before you draw them.

I was just commenting that loading an image in paint() sounds like a bit odd idea as image loading can take quite a long time. Doing the image loading in some init() method would be more appropriate, but that was not the point of the example anyhow...

Maploader? Now I''m getting confused... imageController sounds like a controller of all used images, but what on earth does a maploader do in this mess? Well, anyhow you asked why your example code doesn''t work and after that change it''ll work, so that should answer your original question, right?
0

Share this post


Link to post
Share on other sites
Maploader is actually named wrong, it should be mapCreator, because I''ll create dynamic maps except world and town maps, I once did this with C++ and with that experience I think I''ll do it in different object...
0

Share this post


Link to post
Share on other sites
Something is perfectly messed... while I can draw retangles and ovals I can''t draw image anyhow... None of these examples didn''t work, I quess there is little object structure fault which causes that I can''t draw images on a canvas... Weird huh? That null thing didn''t work I quess I''m now out of ways to do this in this way...

Hey don''t call my thingie mess, It''s not mess, it''s just... complicated...
0

Share this post


Link to post
Share on other sites
Messy, complicated, whatever... Either way in real workplace you would be put to write it again

But hey, this is the reason I''m writing things on my spare time, nobody is watching over the shoulder

One thing came to my mind. Are you sure that a window peer has been created when you load the images? In other words, a window has been shown and it has received addNotify() notification? Or was this only needed for that createImage(int, int) method?
0

Share this post


Link to post
Share on other sites
Yeah, addNotify just throws hhuuge bunch of errors after I runned it, compieler did not error at all... You said you got this working somehow by seeting imageObserver null? Can you throw that one in my E-mail which is Archaon@online.tietokone.fi
0

Share this post


Link to post
Share on other sites