Web Design and Development Forums

Problem with setTimeout in method

This is a discussion on "Problem with setTimeout in method" within the JavaScript Forum section. This forum, and the thread "Problem with setTimeout in method are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > JavaScript Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 22nd, 2008, 15:33   #1 (permalink)
New Member
 
Join Date: Apr 2008
Location: UK
Age: 22
Posts: 1
Question Problem with setTimeout in method

I have been trying to recreate the oldschool game 'breakout' in javascript and have run into a problem which i can't for the life of me figure out.
It involves animation and the functions work correctly when i use the div style directly in the move() function, but as part of my assignment i've been asked to define ball as an object with methods
Here's the script and markup:
Code: Select all
<
html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=iso-8859-1"/>
<title>Web Programming Assignment 2 - Javascript Game</title>
<linkrel = "stylesheet"type = "text/css"href = "style.css"\>
<script>
var lives =2;
var score =0;
var ball;
var position;
var direction;
function initialize()
{
document
.getElementById('lives').innerHTML ="Lives: "+ lives;
document
.getElementById('score').innerHTML ="Score: "+ score;
ball
=new object('ball');
direction
="north";
}
function object(element)
{
this.style = document.getElementById(element).style;
this.move = move;
}
function move(object)
{
var me =this;
if(direction =="north") {
position
= parseInt(object.style.top);
if(position >0) {
position
--;
object
.style.top = position;
setTimeout
(me.move,0);
}
else {
direction
="south";
}
}
if(direction =="south") {
position
= parseInt(object.style.top);
if(position <287) {
position
++;
object
.style.top = position;
setTimeout
(me.move,0);
}
else {
direction
="north";
collide
();
}
}
}
function collide()
{
if(direction =="north")
{
move
();
}
}
</script> </head>
<bodyonload = "initialize()">
<hr/>
<h1>Javascript Game</h1>
<hr/>
<ahref = "#">Home</a>
<p/>
<form>
<divid = "gameBoard">
<divid = "boundary">
<divid = "ball"style = "left:205px;right:210; top:287px;bottom:292;"></div>
<divid = "paddle"></div>
</div>
<divid = "gameControl">
<divid = gameTitle>Breakout Game</div>
<divid = "lives"></div>
<divid = "score"></div>
<inputtype = "button"value = "Start"id = "buttonStart"onclick = "ball.move(ball)">
<br>
<inputtype = "button"value = "Stop"id = "buttonStop">
<br>
<inputtype = "button"value = "End Game"id = "buttonEnd">
<br>
</div>
</div>
</form> </body> </html>
Any help would be greatly appreciated
Emancip8 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 22nd, 2008, 16:30   #2 (permalink)
New Member
 
Join Date: Dec 2007
Location: LA
Age: 48
Posts: 7
Re: Problem with setTimeout in method

For an unknown reason, your code has no spaces where they should be: between element names and attribute names, and between attributes, too. So I just can't make it out when I copy-and-paste it to my Notepad++. Could you attach it as a separate file?
CandyMan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
.call or .apply with setTimeout djeyewater JavaScript Forum 5 Feb 29th, 2008 16:41
setTimeout won't work cheataweb JavaScript Forum 1 Dec 27th, 2006 00:26
The basic method timmytots CSS Forum 1 Nov 26th, 2005 11:47
Method Not Allowed joshcxa PHP Forum 2 Jul 19th, 2005 01:49



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 20:13.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


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