Results 41 to 58 of 58
Thread: game engine trouble
- 06-16-2012, 07:22 PM #41
Member
- Join Date
- Mar 2012
- Posts
- 70
- Rep Power
- 0
- 06-16-2012, 07:35 PM #42
Re: game engine trouble
Without a program that shows the problem, I can't work on a solution.
Build one in the program or attach it to the forum's thread.use the same image as meIf you don't understand my response, don't ignore it, ask a question.
- 06-16-2012, 08:00 PM #43
Member
- Join Date
- Mar 2012
- Posts
- 70
- Rep Power
- 0
Re: game engine trouble
how do you set the apha thing you mentioned
- 06-16-2012, 08:06 PM #44
Re: game engine trouble
Look at the Color class.
If you don't understand my response, don't ignore it, ask a question.
- 06-16-2012, 08:19 PM #45
Member
- Join Date
- Mar 2012
- Posts
- 70
- Rep Power
- 0
Re: game engine trouble
there are no set methods in the color class... so how do you modify the alpha value?
- 06-16-2012, 08:22 PM #46
Re: game engine trouble
See the PixelGrabber class for ways to change colors.
If you don't understand my response, don't ignore it, ask a question.
- 06-16-2012, 08:30 PM #47
Member
- Join Date
- Mar 2012
- Posts
- 70
- Rep Power
- 0
Re: game engine trouble
this class seems to be able to retrieve color and modify it on an image, but how can I use it to make parts of the image opaque?
- 06-16-2012, 08:31 PM #48
Re: game engine trouble
The color's alpha value controls opaqueness.
If you don't understand my response, don't ignore it, ask a question.
- 06-16-2012, 09:09 PM #49
Member
- Join Date
- Mar 2012
- Posts
- 70
- Rep Power
- 0
Re: game engine trouble
this snippet of code is supposed to make a single color transparent, but I dont understand anything but bits and pieces of it. Can you help me to do so? First off, is there a good tutorial somewhere for RGB image filters, b/c I havn't ever used them before. Next the return statement, I don't understand the logic of it or the purpose of the shift operator.
Java Code:private Image TransformGrayToTransparency(BufferedImage image) { ImageFilter filter = new RGBImageFilter() { public final int filterRGB(int x, int y, int rgb) { return (rgb << 8) & 0xFF000000; } }; ImageProducer ip = new FilteredImageSource(image.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(ip); }
- 06-16-2012, 09:20 PM #50
Re: game engine trouble
Where there any comments by the author of the program explaining what it does? I've never used a filter.
To see what the shift operator does, print out the int value before and after the shift to see what if does.
Use the Integer class's toHexString() method to format the int value to see what happens to the bits in the int variable.If you don't understand my response, don't ignore it, ask a question.
- 06-16-2012, 11:52 PM #51
Member
- Join Date
- Mar 2012
- Posts
- 70
- Rep Power
- 0
Re: game engine trouble
I really just want an explination of that return statement at the moment.
here is where I got that code:
java - How to make a color transparent in a BufferedImage and save as PNG - Stack Overflow
- 06-17-2012, 12:25 AM #52
Re: game engine trouble
explination of that return statement at the moment.Read th API doc for the class and method it uses.Java Code:return Toolkit.getDefaultToolkit().createImage(ip);
If you don't understand my response, don't ignore it, ask a question.
- 06-17-2012, 12:28 AM #53
Member
- Join Date
- Mar 2012
- Posts
- 70
- Rep Power
- 0
Re: game engine trouble
not that return statement, the one on line 7. I don't understand why he has hexadecimal numbers there, or why the book that taught me what hexadecimal was said it was used often when working with color values...
- 06-17-2012, 12:57 AM #54
Re: game engine trouble
As I said before add a println statement to print out the values that are created by the shift and & to see what they do. Write a 5 line program that does some shifts and ANDs and print out the before and after to see what happens.
Hexadecimal numbers are easier to understand when used with the AND(&) and OR(|) operators. You can see that the AND is clearing all the bits except for the top (leftmost) 8 bits. You use AND to clear bits and OR to set bits.If you don't understand my response, don't ignore it, ask a question.
- 06-17-2012, 01:40 AM #55
Member
- Join Date
- Mar 2012
- Posts
- 70
- Rep Power
- 0
Re: game engine trouble
I am going to play around with hexadecimal numbers for a bit... In the meantime, I have wracked my brain, but cannot think of any way to do what I need. this program below draws a line from the point (250,250) to wherever you click, a black dot also flies across the screen. Pretend that the player is at the point (250,250). I want to make it so that wherever I click It will fire a black ball in that direction, but I cannot think of a way to do this that will work for every direction. Any thoughts?
Fram:Java Code://this can be used to rid yourself of flickering import java.awt.*; import java.awt.image.BufferStrategy; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.util.Timer; import java.util.TimerTask; import java.awt.Rectangle; import java.io.IOException; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.awt.geom.Ellipse2D.Double; import java.awt.geom.Ellipse2D; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; public class TRYBufferStrategy extends Fram implements MouseListener { Panel base = new Panel(); Canvas canvas = new Canvas(); Timer t = new Timer(); int x=50,y=50, count=0,mx=250,my=250; BufferStrategy strategy; BufferedImage face; Ellipse2D shot = new Ellipse2D.Double(50,50,5,5); TRYBufferStrategy() { super("TRYBufferStrategy"); setSize(800,600); //setIgnoreRepaint(true); add(base); //canvas.setPreferredSize(new Dimension(this.getWidth(),this.getHeight())); setIgnoreRepaint(true); base.setLayout(null); base.add(canvas); canvas.setBounds(0,0,getWidth(),getHeight()); canvas.setIgnoreRepaint(true); canvas.addMouseListener(this); //setUndecorated(true); setVisible(true); try { face = ImageIO.read(getClass().getClassLoader().getResource("pic/hills.jpg")); } catch(IOException e) {} canvas.createBufferStrategy(2); strategy = canvas.getBufferStrategy(); t.schedule(new TimerTask() { public void run() { ++count; strategy = canvas.getBufferStrategy(); do { do { Graphics2D g = (Graphics2D)strategy.getDrawGraphics(); render(g); g.dispose(); }while(strategy.contentsRestored()); strategy.show(); }while(strategy.contentsLost()); if(count==100) { count=0; cancel(); } } },2000,10); } public void render(Graphics2D g2) { x+=5; shot.setFrame(x,(x/5),5,5); g2.drawImage(face,0,0,null); g2.fill(shot); g2.drawLine(250,250,mx,my); } public void mouseClicked(MouseEvent event) { mx= event.getX(); my= event.getY(); t.schedule(new TimerTask() { public void run() { ++count; strategy = canvas.getBufferStrategy(); do { do { Graphics2D g = (Graphics2D)strategy.getDrawGraphics(); render(g); g.dispose(); }while(strategy.contentsRestored()); strategy.show(); }while(strategy.contentsLost()); if(count==1) { count=0; cancel(); } } },0,10); } public void mouseEntered(MouseEvent event) { //System.out.println("enter"); } public void mouseExited(MouseEvent event) { //System.out.println("exit"); } public void mousePressed(MouseEvent event) { //System.out.println("pressed"); } public void mouseReleased(MouseEvent event) { //System.out.println("released"); } public static void main(String[] args) { TRYBufferStrategy a = new TRYBufferStrategy(); } }
Java Code:import java.awt.event.*; import java.awt.*; public class Fram extends Frame implements WindowListener { public Fram(String str) { super(str); addWindowListener(this); } public void windowClosing(WindowEvent e) { System.exit(0); } public void windowClosed(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} }
- 06-17-2012, 02:00 AM #56
Re: game engine trouble
Get rid of Fram, extend JFrame and add this one line:
Java Code:setDefaultCloseOperation(EXIT_ON_CLOSE);
If you don't understand my response, don't ignore it, ask a question.
- 06-17-2012, 02:01 AM #57
Member
- Join Date
- Mar 2012
- Posts
- 70
- Rep Power
- 0
Re: game engine trouble
ikr... but thats unimportant at the moment, do you have any ideas about the previous post?
Last edited by PRW56; 06-17-2012 at 02:08 AM.
- 06-17-2012, 02:57 AM #58
Similar Threads
-
Easy Clip2D Game Engine now posted
By rdjava in forum Reviews / AdvertisingReplies: 3Last Post: 06-03-2011, 05:24 PM -
Easy Clip2D Game Engine now posted
By rdjava in forum Java GamingReplies: 2Last Post: 06-03-2011, 05:18 PM -
Complete Game Engine for beginner and intermediate game programmers
By rdjava in forum Java GamingReplies: 1Last Post: 06-02-2011, 09:29 AM -
Game Engine in Java, is it practical idea?
By chan_nguyen in forum New To JavaReplies: 2Last Post: 09-14-2010, 03:20 PM -
Crate Game Engine 20080323
By JavaBean in forum Java SoftwareReplies: 0Last Post: 03-25-2008, 04:50 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks