GBeebe

Members
  • Content Count

    29
  • Joined

  • Last visited

About GBeebe

  • Rank
    Member

Contact Methods

  • Website URL
    http://www.gbeebe.com
  • Twitter
    @gary_beebe

Profile Information

  • Gender
    Male
  • Location
    Reno, Pennsylvania

Recent Profile Visitors

1308 profile views
  1. The problem may be that the image hasn't loaded yet. Trying to draw an image, before it's loaded, seems to screw it up for the rest of the session. Try this: var explosionImage = new Image(); explosionImage.loaded = false; explosionImage.onload = function() { this.loaded = true; } explosionImage.src = "ExplosionFinal.png"; Then before you try to draw the image, check to see if (explosionImage == true)
  2. For now, I just uploaded them to my site. In the future I plan on converting one to mobile.
  3. I agree with b10b about documenting. I always right something down. The main point of the game, so it doesn't change half way through. Desired mood of the game, funny, scary, serious, etc. Must haves that I need to stick with so I don't forget them. May haves for things I can add but aren't necessary. Then I draw up some dummy placeholder sprites and design a level that incorporates all the must haves. I have a "skeleton" directory with an index.html that includes some .js files that contain my commonly used code for canvas, keyboard/mouse, sound, state machine, etc... I copy that to a new project with my sprites and finally start coding. Just to keep things clean I usually start new files for player and other classes and not code them directly into the main file.
  4. GBeebe

    Pong help

    After you apply speed to the Y, you need to check to see if it's in bounds, if not move it to the edge. I have the variables screenTop and screenHeight which you'll need to replace with your own. Probably 0 (zero) for screenTop and window.innerHeight for screenHeight. this.update = function() { if(this.side == "left") { if(keys.p1.down) { this.y += this.speed; if ((this.y + this.sizeLength) > screenHeight) { this.y = screenHeight - this.sizeLength } } if(keys.p1.up) { this.y -= this.speed; if (this.y < screenTop) { this.y = screenTop; } } }else{ if(keys.p2.down) { this.y += this.speed; if ((this.y + this.sizeLength) > screenHeight) { this.y = screenHeight - this.sizeLength } } if(keys.p2.up) { this.y -= this.speed; if (this.y < screenTop) { this.y = screenTop; } } } } }
  5. context.save(); context.translate(x, y); //location on the canvas to draw your sprite, this is important. context.scale(-1, -1); //This does your mirroring/flipping context.drawImage(spriteImage, sourceX, sourceY, spriteWidth, spriteHeight, 0, 0, spriteWidth, spriteHeight ); //destination x, y is set to 0, 0 (which will be at translated xy) context.restore();
  6. Here's my keyboard snippet: var autoKeyUpCheck = true;function keyDown(e){ e.preventDefault(); //console.log(e.keyCode); //show key code if (key[e.keyCode] == false || key[e.keyCode] == undefined) { key[e.keyCode] = true; key[kAny] = true; } }function keyUp(e){ e.preventDefault(); if (autoKeyUpCheck == true) { key[e.keyCode] = false; key[kAny] = false; } } window.addEventListener('keydown', keyDown, true);window.addEventListener('keyup', keyUp, true);var key = [];var kUp = 38; var kDown = 40;var kLeft = 37; var kRight = 39;var kA = 65;var kD = 68;var kS = 83;var kW = 87;var kX = 88;var kY = 89;var kZ = 90;var kAny = 0;Anywhere in your game you can check if (key[kUp] == true) to see if the player's pressing the up key. (more keys can be added of course). If you want to restrict a player from rapidly tapping a key for shooting at a constant speed or restrict double jumping, you can set autoKeyUpCheck = false; and then set the key value to false when you're ready for another keypress.
  7. That is weird. You're not setting any clipping regions, are you?
  8. I dont use phaser but when I scale my canvas, I do the opposite to my mouse coordinates.
  9. GBeebe

    Full Screen

    Is that from your html's css? Try adding style="margin: 0px, padding: 0px" in your body tag.
  10. I don't know about the .on method. But methods like .onclick allow me to pass the event so I can event.preventDefault (); which stops the browser from doing stuff with the event.
  11. A note on setting the velocity directly: -750 is a pretty high number, if you insist on doing it that way try adjusting it down to something like -100.
  12. Wow, I can't imagine what you're working on, but it sounds like setting the DOM object.style.zIndex properly might do the trick.
  13. Can I ask, real quick, how experienced are you with programming and JavaScript?
  14. This is my collision listener so far, you can play with it. It tells you what 2 bodies collided. In my code, it ignores any collision with a body that doesn't have a userData set. userData is set in the bodyDef, box2d doesn't care what it is: object, number, string, etc. I'm currently assigning it a string ex "player" or "death" <- object that instantly kills player. I don't assign one to solid ground, because there's currently no need for me to do anything when my player touches solid ground 'cause box2d takes care of what I need. var listener = new b2d.b2ContactListener;//console.log(world); listener.BeginContact = function(contact) { var a = contact.GetFixtureA().GetBody().GetUserData() var b = contact.GetFixtureB().GetBody().GetUserData(); //if we have assigned userData to both bodies, it's important enough to check into if (a && { console.log("Collision between: " + a + " & " + ; } } listener.EndContact = function(contact) { //console.log(contact.GetFixtureA().GetBody().GetUserData()); } listener.PostSolve = function(contact, impulse) { } listener.PreSolve = function(contact, oldManifold) { }Also, there's a b2Body.isAwake() function that will return false if the b2Body is "resting", but I haven't gotten into that yet. Much like yourself, I have just started playing with box2d. Sorry if this reply seems too vague for your answer, I'm currently on my lunch break edit: If you want to see if the player touched anything at all, put this in listener.BeginContact. if (a == 'player' || b == 'player') { //do what ever you need there}
  15. maybe this will help? http://www.iforce2d.net/b2dtut/forces I found that doing this: phyPlayer.ApplyImpulse( {'x' : 0, 'y' : -2}, phyPlayer.GetWorldCenter() );Works pretty well. phyPlayer is the body returned by world.CreateBody(myBodyDef); Now, could you tell me how you made your lines?