Show Posts
|
|
Pages: [1] 2
|
|
2
|
Game Development / Newbie & Debugging Questions / Re: profiling
|
on: 2010-06-24 04:28:25
|
As a guess I'd say your output is listing the methods called in each running thread, the number of times it was called and the percentage of total CPU that they each used. But that is just a guess.
As an alternative I'd recommend taking a look at JVisualVM. It'll be a lot easier then profiling via the command line. Goto the bin folder of your JDK (approximately: C:/program files/java/jdk1.6.0_17/bin) and you should see 'jvisualvm.exe'. Run it and wait for it to open. Then run your game/app and it'll appear listed on the left. You then double click on it to get JVisualVM to connect.
Once it's connected you can see the memory and GC usage as well as setting it up to profile your app in greater detail.
Ok thanks, I'll try it out now! Edit: I have to to say this thing looks pretty cool, I'll get back to you once I understand how to read the charts in it, for some reason the "Memory" in the profiler is taking ages to load(still not loaded) but other things look good. Thanks again for the help =)
|
|
|
|
|
3
|
Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem
|
on: 2010-06-22 15:57:29
|
I think I got rid of flickering, can someone please be kind enough to check if you still get flickering when scrolling from my game? For some reason making it full screen seems to do the trick....I have no idea why... Link to code, the zip file contains 3 jars, just different way of doing things: http://www.mediafire.com/?mndtjmninztHere's the code highlight for each jar, note that my screen has a resolution of 1024 * 768, scrolling is done by moving mouse to left/right edge of the screen: - Sof_FS.jar is the first full screen method I tried 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| GraphicsDevice gd;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration();
final int currentRefreshrate = gd.getDisplayMode().getRefreshRate(); System.out.println("Reported Refreshrate=" + currentRefreshrate); targetFps = (currentRefreshrate==DisplayMode.REFRESH_RATE_UNKNOWN?60:currentRefreshrate); Frame frame = new Frame(gc); frame.setIgnoreRepaint(true); frame.setUndecorated( true ); frame.setLayout(null); setIgnoreRepaint(true); setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT); frame.add(this); frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT); frame.setFocusTraversalKeysEnabled(false); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setVisible(true); gd.setFullScreenWindow(frame); if( gd.isDisplayChangeSupported() ) { gd.setDisplayMode( new DisplayMode( WINDOWS_WIDTH, WINDOWS_HEIGHT, 32, DisplayMode.REFRESH_RATE_UNKNOWN ) ); } |
- Sof_FS2.jar is the second full screen method I tried: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Frame frame = new Frame("Test Scroller"); frame.setLayout(null); setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT); frame.add(this); frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); createBufferStrategy(2); strategy = getBufferStrategy();
GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(frame); |
- SoF.jar, the non-full screen mode: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| Frame frame = new Frame("Side Scroller"); frame.setLayout(null); setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT); frame.add(this); frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); createBufferStrategy(2); strategy = getBufferStrategy(); |
|
|
|
|
|
4
|
Game Development / Newbie & Debugging Questions / profiling
|
on: 2010-06-22 08:18:45
|
Dear JGO Members, I've read the guide in the java2D section about profiling, I've tried passing the variables as argument in Eclipse but still can't get it to work. Sorry that I'm pretty new to profiling it would be really nice if someone can shade me some light on how profiling works. Thanks in advance! Edit: After abit more search I found out -Xpro can do profiling, did it on CMD, but I'm not sure exactly what those mean, like what's good it terms of performance and whats bad? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| C:\>java -jar -Xprof GGt.jar
Flat profile of 34.68 secs (3128 total ticks): AWT-Windows
Interpreted + native Method 99.7% 0 + 3119 sun.awt.windows.WToolkit.eventLoop 0.1% 2 + 0 sun.awt.AWTAutoShutdown.setToolkitBusy 0.0% 1 + 0 sun.reflect.NativeMethodAccessorImpl.invoke 0.0% 1 + 0 sun.awt.SunToolkit.wakeupEventQueue 0.0% 0 + 1 java.lang.Object.hashCode 0.0% 0 + 1 sun.awt.windows.WToolkit.init 99.9% 4 + 3121 Total interpreted
Compiled + native Method 0.1% 0 + 3 sun.awt.AWTAutoShutdown.setToolkitBusy 0.1% 0 + 3 Total compiled
Flat profile of 0.11 secs (7 total ticks): Thread-1
Interpreted + native Method 100.0% 0 + 7 sun.awt.windows.WToolkit.shutdown 100.0% 0 + 7 Total interpreted
Flat profile of 34.70 secs (3127 total ticks): AWT-EventQueue-0
Interpreted + native Method 31.0% 0 + 26 sun.awt.windows.WFramePeer.setState 23.8% 0 + 20 sun.awt.windows.WGlobalCursorManager.setCursor 13.1% 0 + 11 sun.awt.windows.WGlobalCursorManager.findHeavyweightUnd erCursor 9.5% 0 + 8 sun.awt.windows.WComponentPeer.nativeHandleEvent 8.3% 1 + 6 sun.awt.Win32GraphicsDevice.enumDisplayModes 1.2% 0 + 1 java.lang.Thread.holdsLock 1.2% 0 + 1 java.lang.Object.clone 1.2% 0 + 1 java.lang.Class.getInterfaces 1.2% 0 + 1 sun.awt.windows.WComponentPeer.reshape 1.2% 0 + 1 sun.java2d.loops.FillRect.FillRect 1.2% 0 + 1 sun.java2d.windows.GDIBlitLoops.nativeBlit 1.2% 1 + 0 java.awt.DisplayMode.<init> 1.2% 1 + 0 sun.awt.AWTAutoShutdown.notifyThreadBusy 1.2% 1 + 0 java.awt.Window.processWindowEvent 1.2% 1 + 0 java.awt.EventQueue.setCurrentEventAndMostRecentTimeImp l 97.6% 5 + 77 Total interpreted
Compiled + native Method 1.2% 1 + 0 sun.awt.AppContext.get 1.2% 1 + 0 Total compiled
Stub + native Method 1.2% 0 + 1 java.lang.Thread.currentThread 1.2% 0 + 1 Total stub
Thread-local ticks: 97.3% 3043 Blocked (of total)
Flat profile of 34.78 secs (3134 total ticks): AWT-Shutdown
Thread-local ticks: 100.0% 3134 Blocked (of total)
Flat profile of 34.80 secs (3136 total ticks): Java2D Disposer
Thread-local ticks: 100.0% 3136 Blocked (of total)
Flat profile of 34.88 secs (3142 total ticks): main
Interpreted + native Method 2.9% 0 + 92 sun.nio.ch.FileDispatcher.read0 1.9% 0 + 61 sun.java2d.windows.GDIBlitLoops.nativeBlit 1.1% 0 + 36 sun.java2d.loops.Blit.Blit 0.4% 0 + 14 sun.java2d.loops.FillRect.FillRect 0.4% 0 + 13 java.io.RandomAccessFile.close0 0.2% 0 + 5 java.io.RandomAccessFile.open 0.2% 5 + 0 java.awt.image.DataBufferByte.<init> 0.2% 0 + 5 java.util.zip.Inflater.inflateBytes 0.1% 0 + 4 sun.font.FontManager.populateFontFileNameMap 0.1% 0 + 3 sun.font.FileFont.getGlyphImage 0.1% 3 + 0 java.lang.AbstractStringBuilder.<init> 0.1% 0 + 3 sun.java2d.loops.DrawGlyphList.DrawGlyphList 0.1% 0 + 2 java.lang.Throwable.fillInStackTrace 0.1% 1 + 1 sun.java2d.loops.MaskBlit.MaskBlit 0.1% 2 + 0 java.awt.image.DataBufferInt.<init> 0.1% 2 + 0 com.sun.imageio.plugins.png.PNGImageReader.decodePaethF ilter 0.0% 1 + 0 sun.font.TrueTypeFont.close 0.0% 0 + 1 sun.awt.windows.WWindowPeer.reshapeFrame 0.0% 1 + 0 sun.java2d.SunGraphics2D.drawImage 0.0% 1 + 0 sun.net.www.protocol.file.Handler.createFileURLConnecti on 0.0% 0 + 1 java.io.RandomAccessFile.seek 0.0% 0 + 1 sun.awt.Win32GraphicsDevice.enterFullScreenExclusive 0.0% 0 + 1 java.lang.reflect.Array.newArray 0.0% 0 + 1 java.io.WinNTFileSystem.list 0.0% 1 + 0 java.awt.Rectangle.setBounds 9.4% 43 + 251 Total interpreted (including elided)
Compiled + native Method 50.7% 1591 + 0 java.awt.image.ComponentColorModel.getRGBComponent 16.8% 529 + 0 java.awt.image.ComponentColorModel.getRGB 15.4% 485 + 0 sun.awt.image.ByteInterleavedRaster.getDataElements 3.5% 110 + 0 sun.java2d.loops.OpaqueCopyAnyToArgb.Blit 1.0% 30 + 0 com.sun.imageio.plugins.png.PNGImageReader.decodePaethF ilter 0.2% 7 + 0 com.sun.imageio.plugins.png.PNGImageReader.decodeUpFilt er 0.0% 1 + 0 java.io.BufferedInputStream.read 0.0% 1 + 0 com.sun.imageio.plugins.png.PNGImageReader.decodePass 0.0% 1 + 0 Map.Map.paint 87.7% 2755 + 0 Total compiled
Stub + native Method 2.2% 0 + 69 sun.java2d.loops.MaskBlit.MaskBlit 0.4% 0 + 12 java.util.zip.Inflater.inflateBytes 0.2% 0 + 7 java.lang.System.arraycopy 0.1% 0 + 2 java.lang.Thread.currentThread 0.0% 0 + 1 java.io.RandomAccessFile.readBytes 2.9% 0 + 91 Total stub
Thread-local ticks: 0.0% 1 Blocked (of total) 0.0% 1 Class loader
Global summary of 34.88 seconds: 100.0% 3163 Received ticks 0.7% 21 Received GC ticks 0.2% 7 Compilation 0.0% 1 Class loader |
|
|
|
|
|
5
|
Game Development / Newbie & Debugging Questions / Re: Sprite Alpha
|
on: 2010-06-22 04:06:27
|
If your doing what I'm thinking you are doing then you can try this, this allows you to change the transparency on an image, preferably a png: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| float transperancy = 0;
public BufferedImage drawAlpha() { BufferedImage loaded = ImageIO.read(new File("images/buildings/g_u_1.png"));
BufferedImage aimg = new BufferedImage(loaded.getWidth(), loaded.getHeight(), BufferedImage.TRANSLUCENT);
Graphics2D g = aimg.createGraphics();
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transperancy));
g.drawImage(loaded, null, 0, 0);
g.dispose(); return aimg; } |
And this is how you would draw it, the transparent value has a range from 1.0 ~ 0.0, hope it helps.: 1 2 3
| public void paint(Graphics2D g) { g.drawImage(drawAlpha(), x, y, width, height, null); } |
|
|
|
|
|
7
|
Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem
|
on: 2010-06-21 06:34:50
|
im trying something similar and I think what we need is a way to do vsync, I asked for that in other post, I hope someone give an answer. Does vsync get rid of flickering? I'm using double buffering and I still get flickering. It would be really nice if someone can show me how to do scrolling properly, perhaps my way of doing it is just wrong. The way I scroll is to have screen follow this "camera(an invisible rectangle) and when I move mouse to the left/right edges of the screen it increments/decrements the X position of the camera and as an end result the map scrolls. I noticed in my games when ever I scroll right my character "shifts back" a little bit when he's near the edge, perhaps this will lead to the root cause of my weird flickering bug. Edit: I tried it, still doesn't get rid of flickering and I'm not sure whats wrong with my scrolling code. Here's how I do scrolling in case anyone's interested: I have 2 variables to tell where the camera is at now, lets forget about Y for now since I'm only doing horizontal scrolling. VisibleX is declared as public static int visibleX = GameCore.WINDOWS_WIDTH / (8 * Map.TILE_SIZE); Where WINDOWS_WIDTH is 1024(my screen width); and camera.x is camera's current position. Cornershift is just to shift edges according to player's position so that things outside of the actual map won't be seen. 1 2 3
| mapPosX = Camera.visibleX - Camera.x; mapPosY = Camera.visibleY - Camera.y; cornerShift(); |
Then this is how I calculate the offset to be used for all scrolling 1 2 3 4 5 6 7 8
| int offsetX = (int)((GameCore.mapPosX + GameCore.fixX)* Map.TILE_SIZE);
int offsetY = (int)((GameCore.mapPosY + GameCore.fixY) * Map.TILE_SIZE);
g.drawRect(xp + offsetX, yp + offsetY, width, height);
|
I've tried all sorts of game loop today, tried running the game in full screen/windowed application as well and different methods posted on forum to get rid of flickering. I can't really find any bugs/flaws in my scrolling method and none of the methods I tried work so far, any help would be greatly appreciated.
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem
|
on: 2010-06-19 08:26:45
|
EDIT: I found the problem, it has nothing to do with the game loop at all, there's something wrong with my scrolling offset, I'll try and fix it now. Thanks for the help! I tried the method adon_y_coya suggested but the flickering is still there =/. I'm just curious, what are the possible causes that could cause flickering in java? Here's the code for my frame: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Frame frame = new Frame("Stone of Franks"); Panel panel = new Panel(); panel.setLayout(null); Canvas canvas = new Canvas(); canvas.setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT); canvas.setIgnoreRepaint(true); panel.add(canvas); frame.add(panel);
frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setVisible(true); canvas.createBufferStrategy(2); strategy = canvas.getBufferStrategy(); canvas.requestFocus(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
canvas.addKeyListener(this); canvas.addMouseListener(this); canvas.addMouseMotionListener(this); |
|
|
|
|
|
9
|
Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem
|
on: 2010-06-18 11:24:55
|
Put a panel in your frame (and set layout null) then put a canvas in that panel and setIgnoreRepaint(true) and have the canvas createBufferStrategy(2) and then request focus. That solved all flickering issues I've had.
Thanks for the reply! I'll try that when I get home. I'm not using any swing components tho will that be fine?
|
|
|
|
|
11
|
Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem
|
on: 2010-06-17 09:41:21
|
Hey Riven, Thanks for the fast reply, this is what the gameRender() looks like, sorry but what is EDT? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| GameCore() { Frame frame = new Frame("Side Scroller"); frame.setLayout(null); setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT); frame.add(this); frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.addKeyListener(this); addKeyListener(this); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
createBufferStrategy(2); strategy = getBufferStrategy();
setFPS(); gameLoop(); }
private void gameRender() { Graphics2D g = (Graphics2D) strategy.getDrawGraphics(); g.setColor(Color.WHITE); g.fillRect(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT); g.translate(0, 10);
if(player.isAlive() && gameStart) { map.paint(g); spawn.paint(g); powerUp.paint(g); player.paint(g); gui.paint(g); }
scene.paint(g); g.dispose(); strategy.show(); } |
Edit: I'm trying to keep the game single threaded to keep it as simple as possible. I'm not very good with multi-threading yet. Edit 2: The silhouette only happens on the g.fillRect() Rectangles, the images don't have that effect and it only happens when I'm scrolling. Edit 3: The paint(g) code is something like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public void paint(Graphics2D g) { for(int i = spellList.size() - 1; i >= 0 ; i--) { spellList.get(i).paint(g); } for(int i = explosion.size() - 1; i >= 0; i--) { if(explosion.get(i).Length() != 0) { explosion.get(i).paint(g); } }
g.drawImage(anim.getCurrentImage(), xp + offsetX - 10, yp + offsetY, null); } |
|
|
|
|
|
12
|
Game Development / Newbie & Debugging Questions / Scrolling 2D Image problem
|
on: 2010-06-17 09:29:46
|
Dear JGO Members, I'm having this weird problem when doing side scrolling at a fast speed, the rectangles drew with g.fillRec() start to have some sort of silhouette and images flashes, I have tried to use variable framerate game loop or increase fps in the fixed framerate loop but neither works. The following is an attempt to demonstrate the problem: Flashing when moving 1 http://www.youtube.com/watch?v=aS6LF9GNkjMFlashing when moving 2 http://www.youtube.com/watch?v=aS6LF9GNkjMPicture to show where the silhouette is when scrolling:  Uploaded with ImageShack.usI'm not exactly sure what the cause of the problem is since it looks fine if I scroll at slower speed, I'm guess the problem has to do with the game loop I'm using, note that I want to have a fixed framerate game loop. Below is the code of the loop, thanks in advance! The loop is taken from here: Fixed Framerate loop http://wiki.games4j.com/wiki/en/Timing_in_main_loops1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| private int fps; private long timeThen;
private void setFPS() { fps = 60; timeThen = System.nanoTime(); }
public void sync() { long gapTo = 1000000000L / fps + timeThen; long timeNow = System.nanoTime(); while (gapTo > timeNow) { try { Thread.sleep(1); } catch (InterruptedException e) {} timeNow = System.nanoTime(); } timeThen = timeNow; }
private void gameLoop() { long currentUpdateTime = System.nanoTime(); long lastUpdateTime; while(gameRunning) { lastUpdateTime = currentUpdateTime; currentUpdateTime = System.nanoTime(); long elapsedTime = (currentUpdateTime - lastUpdateTime)/(1000*1000); gameUpdate(elapsedTime); gameRender(); sync(); } } |
|
|
|
|
|
16
|
Game Development / Game Mechanics / Particle Explosion
|
on: 2010-04-21 04:08:52
|
|
Hi, I'm not sure if this is the right section for this kind of stuff, but I'll post here anyway. I have an explosion class that draws lots of particles moving in random direction and forms a square explosion shape, I'm just wondering if there is a formula or algorithm I can use to create a circular explosion shape. Thanks in advance!
|
|
|
|
|
18
|
Game Development / Newbie & Debugging Questions / Re: Load large background image
|
on: 2010-03-27 07:29:35
|
|
Scrolling background causes no lag now thanks alot for the help guys!
Edit: It still causes minor lag when I try to load more parts of the same image, but I'll try fix that.
Edit2: Load large background Image is making my graphics card's fan pretty loud, why is that? I can play some pretty graphics intensive games like crysis, fallout3 and the fan would be abit loud, but aren't 2D games less graphics intensive?
|
|
|
|
|
20
|
Game Development / Newbie & Debugging Questions / Re: Load large background image
|
on: 2010-03-26 02:29:13
|
|
Hi guys, thanks alot for the replies! I have loaded the background image into an array first( tiles are in a separate array). I'll try the drawImage(Image largeBackgroundImage,sx,sy,sx2,sy2,dx,dy,dx2,dy2,null) method as soon as I get off work. I'm just curious, what's better for performance: - drawImage(Image largeBackgroundImage,sx,sy,sx2,sy2,dx,dy,dx2,dy2,null) - getSubImage from bufferedImage(seems like this is really bad for performance) - store the image into an int array like suggested int array[2363 X 1265], althought I'm not quite sure how to do this one, do you mean store the pixels into the array?
Again, thanks alot for the help guys!
|
|
|
|
|
21
|
Game Development / Newbie & Debugging Questions / Load large background image
|
on: 2010-03-25 14:49:09
|
Hi, this probably came up before, but I'm just wondering how are you guys dealing with loading large background images? I have a tile based map and my entire map is consist of 72 X 72 tiles, I have no problem building the map, just when it comes to loading a large background its lagging my game pretty badly. How would you guys load an 2363 X 1265 background image? I've thought about chopping it into blocks, but that would be harder to do parallel scrolling, my idea is use the getSubImage method from the bufferImage to do the scrolling, but with large image lagging my game this doesn't seem viable. Any tips welcome, thanks in advance. 
|
|
|
|
|
22
|
Game Development / Newbie & Debugging Questions / Re: help with scrolling terrain
|
on: 2010-03-23 03:59:43
|
I assume vertical scrolling is working correctly already, all you have to do is change the scrolling Y to scrolling X and there's your horizontal scrolling. You probably also want to change your maps to fit horizontal scrolling. Your current map: ________ | | | | | | | | | | | | |_______| Change to: __________________ | | | | | | |_________________| Hope that helps, if you still don't get it try this site, its written in flash, but the concept is the same. http://www.tonypa.pri.ee/tbw/start.html
|
|
|
|
|
24
|
Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope
|
on: 2010-03-11 03:18:02
|
Well - what was it?
Also, congrats on finding it! Way to persevere.
The problem was at the if statement that checks if player is moving from a higher tile onto a slope. I made some slight modifications and added (int) cast to the check and it works  There are still some minor bugs like mini screen shake when moving on slope and the moving from slopt -> higher tile not playing the correct running animation(it plays jumping), but other than that the slope is looking good, now I need to work on shifting player from Map 1 to a different map and I have a half working game  Thanks again for the help! This here fix the jump bug: 1 2 3 4 5
|
if(map.onSlope(tileX, tileY + 1) && !jumping) { py = tileY + 0.4f; } |
Here's the working code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| int prevSlopeType = -1; private void checkSlope(float x, float y) { float checkX = x + sizeW / 2; float checkY = y + sizeH; int tileX = (int)checkX; int tileY = (int)checkY; int slopeType = map.slopeStyle(tileX, tileY); if(map.onSlope(tileX, tileY + 1) && !jumping) { py = tileY + 0.4f; } if(map.onSlope(tileX, tileY) && !(jumping && jumpDistance < 0)) { onSlope = true; jumping = false; idle = false; float xpos = checkX - tileX; if(slopeType == Map.SLOPE_L) { prevSlopeType = Map.SLOPE_L; py = tileY + 1 - sizeH - xpos; } if(slopeType == Map.SLOPE_R) { prevSlopeType = Map.SLOPE_R; py = tileY + 1 - sizeH - (1 - xpos); } } else { if((prevSlopeType == Map.SLOPE_L && faceDir == States.RIGHT) || (prevSlopeType == Map.SLOPE_R && faceDir == States.LEFT)) { py = tileY - sizeH - 0.1f; } onSlope = false; prevSlopeType = Map.NOT_ON_SLOPE; } }
|
|
|
|
|
|
26
|
Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope
|
on: 2010-03-07 04:42:22
|
my 2cents help... as I did not really not understand the whole stuff  according to your draw and if I understand right... may be this one is wrong : 1 2 3
| } else if(map.onSlope(x + sizeW / 2, y + 1) && !jumping) { onSlope = true;
|
no ? "y+1" may be replaced by "y-1 or - 2 - 3" ? or something like that "y + 1" is intended to check for slope below player, wouldn't y-1, -2 be checking the slope above player? I think my problem happens when entering/exiting the slope, so I'm doing the check suggested by Nate now and I'll post back with the results. Thanks again for the help =) Here are the test results: Note: - checkX/checkY is the X/Y position to check slope collision(where the white square is) - onSlope is a boolean to tell if player is currently on a slope - playerX/playerY is the current position of player(top left of the blue square) 1) Entering slope from a higher tile, from tile 6 -> 7 in X direction, tile 2 -> 3 in Y direction  checkX checkY onSlope playerX playerY 6.0249996 2.96 false 5.7 2.31 6.0249996 2.96 false 5.7 2.31 6.0249996 2.96 false 5.7 2.31 6.0249996 2.96 false 5.7 2.31 6.0249996 2.96 false 5.7 2.31 2) When player X is somewhere near 6.0, the jump bug occurs (5.99999999..../6.0111111111..... will cause this problem too) checkX checkY onSlope playerX playerY 6.325 2.96 false 6.0 2.31 6.325 2.96 false 6.0 2.31 6.325 2.96 false 6.0 2.31 6.325 2.96 false 6.0 2.31 6.325 2.96 false 6.0 2.31 6.325 2.96 false 6.0 2.31 6.325 2.96 false 6.0 2.31 6.325 3.8730001 true 6.0 2.3249998 6.325 2.975 false 6.0 2.3249998 6.325 2.975 false 6.0 2.3249998 6.325 2.975 false 6.0 2.3249998 6.325 2.975 false 6.0 2.3249998 6.325 2.975 false 6.0 2.3249998 6.325 3.8525 true 6.0 2.3249998 3)From playerX = 6.1 onwards everything is fine, the first couple onSlope = false is when player is falling onto the slope.  checkX checkY onSlope playerX playerY 6.4249997 2.96 false 6.1 2.31 6.4249997 2.96 false 6.1 2.31 6.4249997 2.96 false 6.1 2.31 6.4249997 2.96 false 6.1 2.31 6.4249997 2.96 false 6.1 2.31 6.4249997 2.96 false 6.1 2.31 6.4249997 2.96 false 6.1 2.31 6.4249997 3.8725 true 6.1 2.4249997 6.4249997 3.0749998 true 6.1 2.4249997 . . . . . 6.4249997 3.0749998 true 6.1 2.4249997
|
|
|
|
|
28
|
Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope
|
on: 2010-02-28 04:16:48
|
I think I've found the problem of my jumping bug, its actually the problem of my slope checking method. I'll explain with a picture so its easier to understand. - The blue square is the player, and the center buttom white square is my check point used to check for slope(highlighted by green circle) -The part highlighted by red circle is where my problem is. The Slope method works fine in picture 1 and 2, I can move up and down, jump on the slope and its all working fine. I think in picture 3 its suppose start shifting player to the correct Y displacement, but for some reason the onSlope boolean is false(only shift player if its true) and player shifting never takes place until step 4. I have tried adding an if statement to check if the re is a slope below the player when he's moving from a high tile onto slope but that didn't work out either. I've spent days on this problem so any help would be greatly appreciated. Thanks in advance! if statement to check if a player is moving from a high tile onto slope 1 2 3 4
| if(map.onSlope((int)checkX, (int)y + sizeH)) { onSlope = true; moveY(moveSpeed); } |

|
|
|
|
|
29
|
Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope
|
on: 2010-02-26 14:52:07
|
This will probably exceed the word limit of a post so I post the collision part here. Code to move player, inside it "validLocation" checks the collision( this is from Kevin Glass's tutorial at coke and code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| public boolean moveX(float dx) { float nx = px + dx; if (validLocation(nx, py)) { px = nx; return true; } return false; } public boolean moveY(float dy) { float ny = py + dy; if (validLocation(px, ny)) { py = ny; return true; } return false; }
|
Collision Check code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| private boolean validLocation(float nx, float ny) { if(!onSlope) { if (map.blocked(nx, ny)) { return false; } if (map.blocked(nx + sizeW, ny)) { return false; } if (map.blocked(nx, ny + sizeH)) { if(jumping) { jumping = false; jumpDistance = 0; idle = true; } return false; } if (map.blocked(nx + sizeW, ny + sizeH)) { if(jumping) { jumping = false; jumpDistance = 0; idle = true; } return false; } } return true; }
|
|
|
|
|
|
30
|
Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope
|
on: 2010-02-26 14:45:29
|
Hm, well shouldn't the jumping be linked to a button press, so he can't jump if no button is being pressed at all?
Also your code seems to be weirdly coupled, which will give you lots of problems. Collision, jumping, etc. should all be separate, not mashed together like that. Something like the pseudo code below:
Does that maybe enlighten you at all?
Thanks for the reply Demonpants! Thanks for the pseudo code too! Actually I do link jumping to a button, below I'll post my code for the missing part of my code. Also the fallCheck method from previous post is to check whether a player is standing on a walkable tile or not, if not then it moves player down, the actual jumping still requires a player to press the space bar. Handle key for jumping 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE && !jumping && !attacking && !pressSpace) { space = true; pressSpace = true; } } public void keyReleased(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_SPACE) { space = false; pressSpace = false; } }
|
And in the actual update method 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public void update(long elapsedTime) { float dx = 0, dy = 0; moveSpeed = 0.1f; moveSpeed *= elapsedTime * 0.05f;
if(space && !jumping) { if(anim.getCurrentState() == States.ATTACKING || anim.getCurrentState() == States.HIT) { } else { idle = false; jumping = true; jumpDistance = maxJumpHeight; } }
jump(elapsedTime); } |
jump method is called here 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| private void jump(long elapsedTime) { if(jumping) { idle = false; jumpDistance += gravity; if(jumpDistance < 0) { if(validLocation(px, py - moveSpeed)) { moveY(-moveSpeed); } else { jumpDistance = 0; } } else if(jumpDistance > 0) { moveY(moveSpeed); } if(States.JUMPING > anim.getCurrentState()) { anim.setCurrentState(States.JUMPING); } updateAnim(elapsedTime); } }
|
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|