Uhfgood Posted September 8, 2014 Share Posted September 8, 2014 Okay so I rewrote some of my asteroid code for my game, and I can reproduce the problem I had before. Basically I have some visibility code that sets a sprite's visible flag to false when off screen and true when back on the screen, only problem is somehow the physics bodies don't update that fast, and leaves them on the screen. This was causing the player's ship to explode when you couldn't see the asteroid on the screen. I'm not sure why it does this, but I found out by drawing out the bodies with the debug functions, and then logging collisions to the console, so you can collide with these physics bodies that remain on screen. So then the question here is, how do I get it to remove the bodies (or update them to the correct position) immediately. If I disable the physics body it stops updating and the asteroid will remain on screen. In any case you can see this phenomenon here - https://dl.dropboxusercontent.com/u/32895233/sroids/index.html this doesn't function as a game, but you can move around the screen. Try not to get hit by the moving asteroids but try to touch the bodies that start accumulating on the outer edge of the screen. Also you can find the source (easier in zip form) here - https://dl.dropboxusercontent.com/u/32895233/sroids.zip Look at Asteroid.js (lines 179 - 185) and Game.js Let me know what you think. Link to comment Share on other sites More sharing options...
Thigydaze Posted September 9, 2014 Share Posted September 9, 2014 If you're not after absolute precision, I'd be tempted to let the collision event fire, then use the ship x,y coordinates to decide if it's ok to blow it up. If the ship is outside of the visible bounds then exit the collision handler, otherwise... Boom. Link to comment Share on other sites More sharing options...
lewster32 Posted September 9, 2014 Share Posted September 9, 2014 The body and the sprite will always be slightly out of sync the faster the object moves - if your code relies on the accuracy of the position of the body, then you could try using the body's x and y position rather than the sprite's for your visibility calculation maybe? Link to comment Share on other sites More sharing options...
JUL Posted September 9, 2014 Share Posted September 9, 2014 Well...Just launched it on my poor macbook pro snow leapoard with firefox... Got 2 fps, took around a minute to close the window... Glad I had not to kill the browser because I was downloading some stuff with it. But I was one inch away from total freeze. So yeah, debug mode probably slows things down... But to that point... Nah, something is utterly wrong, somewhere. For instance I have a game with 24 bot soldiers firing at each others with machine guns on a giant tilemap, auto detecting their respective postions to know who's closer from who and when to fire or not... (which as you can imagine, takes a lot of rays and various conditions), and with debug mode activated, sure the game is slower, but not to that point. Don't know exactly what is taking so much. Link to comment Share on other sites More sharing options...
Recommended Posts