Results 1 to 9 of 9

Thread: Javascript Collision detection using ID's

  1. #1
    enox10mx is offline x10Hosting Member
    Join Date
    Jan 2012
    Posts
    29

    Javascript Collision detection using ID's

    Hello.
    I am making a game with javascript, and need to know how to make two images touch each other.
    Each image is inside a div with an ID of:
    Code:
    player
    or
    Code:
    wall
    .
    Here is the page's code:
    HTML Code:
    <head><style>DIV.movable { position:absolute; }</style><script type="text/javascript" src="http://www.openjs.com/scripts/events/keyboard_shortcuts/shortcut.js"></script></head><body><div id="player" class="movable"><img src="http://eno.x10.mx/favicon_pakkit.png"></div>
    <br />
    <br />
    <div id="wall" class="movable"><img src="wall.png"></div>
    <br /><script language="javascript">document.getElementById("ufo").style.top  = 1;document.getElementById("ufo").style.left = 1;var position;var pos2;pos2 = 1;position = 1;function movemedown()  {position = position + 5;document.getElementById("ufo").style.top  = position;document.getElementById("ufo").style.left = pos2;}function up()  {position = position - 5;document.getElementById("ufo").style.top = position;}function left()  {pos2 = pos2 - 5;document.getElementById("ufo").style.left = pos2;}function right()  {pos2 = pos2 + 5;document.getElementById("ufo").style.left = pos2;}shortcut.add("Ctrl+Down",function() {    movemedown();});shortcut.add("Ctrl+Up",function() {    up()});shortcut.add("Ctrl+Left",function() {    left();});shortcut.add("Ctrl+Right",function() {right();});</script><br /><br /><br /><br /><br /></body>
    Ignore the "shortcut.add" and the excessive BR's, but that's my page.
    May somebody help me do collision checking.
    Last edited by enox10mx; 04-11-2012 at 04:18 PM.
    -by htmlguy999: youtube.com/htmlguy999

  2. #2
    miguelkp's Avatar
    miguelkp is offline x10 Lieutenant
    Join Date
    Oct 2009
    Location
    El Bierzo - Spain
    Posts
    306

    Re: Javascript Collision detection using ID's

    I guess you should give this a try:

    http://gamequeryjs.com/

    gameQuery is an easy to use jQuery plug-in to help make javascript game development easier by adding some simple game-related classes. If you know how to use jQuery you almost know how to use gameQuery! To learn more go to the documentation page. The project is hosted on GitHub and you can follow it on a twitter page for the daily progress of the development.

    gameQuery has the following features:
    1. multi layer-sprite animations
    2. sprite hierarchies (grouping)
    3. collision detection
    4. swappable sound support
    5. periodic callbacks
    6. keyboard state polling
    7. free and open source license
    Last edited by miguelkp; 04-10-2012 at 05:32 PM.
    Clic on userbar to visit my band's website:

  3. #3
    enox10mx is offline x10Hosting Member
    Join Date
    Jan 2012
    Posts
    29

    Re: Javascript Collision detection using ID's

    What is jquery?
    -by htmlguy999: youtube.com/htmlguy999

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    8,349

    Re: Javascript Collision detection using ID's

    http://jquery.com/

    jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
    Nothing is always absolutely so.

  5. #5
    enox10mx is offline x10Hosting Member
    Join Date
    Jan 2012
    Posts
    29

    Re: Javascript Collision detection using ID's

    I figured that out before i looked at the answer here by googling it.
    I find it useless anyway because I cannot find the collision detection function.
    May somebody please give me the code for a function that runs another function when objects with certain ID's hit each other.
    example for a function:
    Code:
    onhit("id1","id2","dothisfunction();");
    -by htmlguy999: youtube.com/htmlguy999

  6. #6
    miguelkp's Avatar
    miguelkp is offline x10 Lieutenant
    Join Date
    Oct 2009
    Location
    El Bierzo - Spain
    Posts
    306

    Re: Javascript Collision detection using ID's

    Quote Originally Posted by enox10mx View Post
    I find it useless anyway because I cannot find the collision detection function.
    Then I guess you didn't look for it too much:

    http://gamequeryjs.com/documentation/api/#collision
    Clic on userbar to visit my band's website:

  7. #7
    enox10mx is offline x10Hosting Member
    Join Date
    Jan 2012
    Posts
    29

    Re: Javascript Collision detection using ID's

    May somebody please give me the code for a function that runs another function when objects with certain ID's hit each other.
    example for a function:
    Code:
    onhit("id1","id2","dothisfunction();");
    Please may somebody post some code as I described.
    -by htmlguy999: youtube.com/htmlguy999

  8. #8
    matt_a_nice_guy_200061 is offline x10Hosting Member
    Join Date
    Jun 2011
    Posts
    11

    Re: Javascript Collision detection using ID's

    Writing collision detection a.k.a. does x overlap y (or would it if the items continued to move).

    If you're programmatically moving an object around the screen then presumably you know an x,y, location of one of its corners?

    If you know an (x,y) co-ord, and you know both the height and width of the object then you can use that information to compute if that area is (potentially) occupying the same area as the item you want to know if it's colliding with

  9. #9
    misson is offline x10 Spammer
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,573

    Re: Javascript Collision detection using ID's

    There's good lazy (getting a computer to do your work) and bad lazy (getting a person to do your work). Asking for teh codez is the bad kind of lazy. Research, try to do it yourself, and ask specific questions when you're stuck.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Jon Skeet's and Eric Raymond's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

Similar Threads

  1. Suggestion on the open_basedir/include_path collision
    By 4xware in forum Feedback and Suggestions
    Replies: 0
    Last Post: 10-18-2010, 05:57 AM
  2. Intel Graphics Detection???
    By Sup3rkirby in forum Off Topic
    Replies: 4
    Last Post: 10-22-2008, 11:23 PM
  3. High resource detection script broken?
    By Skizzerz in forum Free Hosting
    Replies: 1
    Last Post: 08-03-2008, 05:14 PM
  4. javascript and external javascript files problem
    By delon in forum Scripts, 3rd Party Apps, and Programming
    Replies: 6
    Last Post: 04-27-2008, 12:41 AM
  5. MD4 and MD5 Collision Source Code Released
    By n4tec in forum Scripts, 3rd Party Apps, and Programming
    Replies: 5
    Last Post: 12-03-2005, 01:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
dedicated servers