Jump to content

Javascript Sprites


cursed

Recommended Posts

Hi all,

 

I was wondering if anyone can help me with this script.

Instead of the sprite going off the page, I want it to still stay inside and to let the background move with it.

 

url: proxyize.com/sprite

(this is in no way trying to advertise my site, i only use it for beta testing ;D)

 

Also (if this is out of scope of this question, let me know) how hard would it be to go and send co'ords to the mySQL database using php/ajax?

 

Thanks in advance,

 

Edward

Link to comment
Share on other sites

I assume you mean this page - http://proxyize.com/sprite/bp.html

 

Pretty damn cool.

 

My idea would be to put that bkg in a div that has its overflow set to hidden and as the sprite gets to either edge, the div scrolls.

 

I havent looked at your js yet, but i assume that you would have to keep track of the position of the sprite in relation to the 0,0 point of the div. And you would also have to count how many "Scrolls" have elapsed so that when the sprite's position is >= (width of div * number of divs elapsed) you'd know to scroll.

 

But that approach is kinda of bad because once you reach the edge you'd have to wait until the bkg scrolled. It might be a better look to have the mouse keys contorl the bkg movement.

Link to comment
Share on other sites

I havent looked at your js yet, but i assume that you would have to keep track of the position of the sprite in relation to the 0,0 point of the div. And you would also have to count how many "Scrolls" have elapsed so that when the sprite's position is >= (width of div * number of divs elapsed) you'd know to scroll.

 

But that approach is kinda of bad because once you reach the edge you'd have to wait until the bkg scrolled. It might be a better look to have the mouse keys contorl the bkg movement.

 

Thanks for the reply, I'll try the overflow = hidden technique.

I'm not sure how to implement the 0,0 point of a div using javascript, can you elaborate on some ways in code on how to do that?

 

Regards,

 

Edward

Link to comment
Share on other sites

Look at this and try to understand what I meant with the second example

 

<div id="container"> //this has the overflow:hidden

<div id="bkg"></div> //this div would be the whole length of the level

</div>

 

Instead of moving the character move the bkg left or right and if you reach the extents of the bkg, then move the character. I dont know YUI to help you how to do this though. does that make sense?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.