JavaScript - Help Animating Video Game Sprites, Akin To Flash Animations
Hello everyone! I found this article over devness: http://devness.com/2009/06/playing-w...animated-menu/
It is fantastic, but I'm a complete n00b and I was wondering what the JavaScript would look like if the situation was a little different. Picture this: A Super Mario sprite with him standing normally, but to his right is the word "Home". Upon roll over of either the sprite itself or the text, mario does one of his trademark jumps by the way of a few sprites. I know how to do this in flash, but I would like to eliminate it so I have maximum compatibility and no external plugins required. Anyone have any ideas or suggestions? Any help is greatly appreciated!! Similar TutorialsHello, I am building a website: http://www.manak.fr My flash slideshows are working everywhere except on Firefox with Mac. Buttons don't seem to work. If you have any idea, thanks a lot. Manuel. (from France) I want to run a flash video on my web site. I've been working on this for days now, and obviously missing something. The page is really BRIEF -- nothing more than <object> calls and swfobject.registerObject call. when I look at it on the server, I get a totally blank page in IE. In firefox, I see a little "block" tab where the movie frame would be if it worked. Here is the whole code: thanks so much for looking at it. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <LINK REL="SHORTCUT ICON" HREF="http://olympiceq.com/favicon.ico"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Olympic Equine</title> </head> <body> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="360" height="264" id="FLVPlayer"> <param name="movie" value="FLVPlayer_Progressive.swf" /> <param name="quality" value="high" /> <param name="wmode" value="opaque" /> <param name="scale" value="noscale" /> <param name="salign" value="lt" /> <param name="FlashVars" value="&MM_ComponentVersion=1&skinName=Corona_Skin_2&streamName=HorseswithClicktoPlay&autoPlay=false&autoRewind=false" /> <param name="swfversion" value="8,0,0,0" /> <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. --> <param name="expressinstall" value="expressInstall.swf" /> <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. --> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="FLVPlayer_Progressive.swf" width="360" height="264"> <!--<![endif]--> <param name="quality" value="high" /> <param name="wmode" value="opaque" /> <param name="scale" value="noscale" /> <param name="salign" value="lt" /> <param name="FlashVars" value="&MM_ComponentVersion=1&skinName=Corona_Skin_2&streamName=HorseswithClicktoPlay&autoPlay=false&autoRewind=false" /> <param name="swfversion" value="8,0,0,0" /> <param name="expressinstall" value="expressInstall.swf" /> <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. --> <div> <h4>Content on this page requires a newer version of Adobe Flash Player.</h4> <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p> </div> <!--[if !IE]>--> </object> <!--<![endif]--> </object> <script type="text/javascript"> <!-- swfobject.registerObject("FLVPlayer"); //--> </script> </body> </html> I have created a transparent flash video (virtual spokesperson) for my website. For demoing purposes, I would like to have this appear on any desired website. This is what I am trying to produce - here a virtual spokesperson appears on the codingforums.com website: http://www.innovateads.com/iads/demo...dingforums.com Have a look at other sites which enable one to type in a URL and their demo virtual spokesperson appears on the given site: http://www.vspworldwide.com, http://www.impactspokesperson.com, http://www.websitetalkingheads.com and http://www.laserstreamvideo.com. I believe they do this within an iframe to display the underlying website. Any ideas how to get this working ? I would really appreciate any feedback, code, how-tos, links... whatever. I am a complete javascript newbie. Thanks is there a way to stop a flash video with jQuery?? I'm using a html5 video with flash fallback.. i'm using the video on a modal pop up.. when i try to hide the video, the flash video doesn't stop... so before i hide the mask, i must stop or pause the video, then hide.. i tried various ways, but i can't seem to make them work.. Code: <video id="480p" width="848" height="480" controls="controls" poster="New_Test_Encodes_7-31-11/Test_Encode_Desktop_7-31-11/poster.jpg"> <source src="New_Test_Encodes_7-31-11/Test_Encode_Desktop_7-31-11/Marie_Mcray_Test-H264_480p.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> <source src="New_Test_Encodes_7-31-11/Test_Encode_Desktop_7-31-11/Marie_Mcray_Test.ogg" type='video/ogg; codecs="theora, vorbis"' /> <!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --> <object id="480pfallback" class="480p" width="848" height="480" type="application/x-shockwave-flash" data="flowplayer/flowplayer-3.2.7.swf"> <param name="movie" value="flowplayer/flowplayer-3.2.7.swf" /> <param name="allowfullscreen" value="true" /> <param name="flashvars" value='config={"playlist":["New_Test_Encodes_7-31-11/Test_Encode_Desktop_7-31-11/poster.jpg", {"url": "New_Test_Encodes_7-31-11/Test_Encode_Desktop_7-31-11/Marie_Mcray_Test-H264_480p.mp4","autoPlay":false,"autoBuffering":false}]}' /> <!-- Image Fallback. Typically the same as the poster image. --> <img src="New_Test_Encodes_7-31-11/Test_Encode_Desktop_7-31-11/Marie_McCray_A_O_poster.jpg" width="848" height="480" alt="Poster Image" title="No video playback capabilities." /> </object> </video><!--480p--> hi, I have created a flash video that work on a php table (like php-nuke), this is seen well on my PC, instead with various screen the video size is not good. ON screen big the video is small, on screen small the video is big... How i can made a script that change the dimension of flash video ? any idea ? please help me.. This is what I have so far which works as a cross-browser download however Firefox will play the video locally inside the popup window: is this normal behaviour? Code: <span class="popup"><a href="javascript:void(window.open('videos/directdrive.flv','','height=383,width=512'));">Watch a video!</a></span> link to the page This is a very new area for me as you can probably tell and I was wondering if websites require a flash player to view video or do some browsers have a flash player built in as Firefox has led me to believe? Thanks. Hi from Ireland! I recently signed up to Google Analytics and it began to block my flash content. I removed the tracker code (javascript) and deleted my account though my flash content is still blocked. Can someone help? I'll buy you a pint. I am not sure if I am in the right section. I tried to search this but couldn't find what I needed. I am very limited on my javascript knowledge. I need a video player that functions almost exactly like the one in this example: http://www.popcap.com/games/bookworm...L_1_8_19_08_en {the links that toggle between the video and flash slideshow depending on which is clicked. The player showing the videos and screenshots for the game}. I tried looking at the source to understand the functions, but my code is not working. I know the player is calling some javascript, but I'm not sure I understand it all. Can someone explain to me the basic functioning of this player as shown? I would very much appreciate it. Hey, I had a question about this script I'm working with. I have two functions which I'm using to grow and shrink a div. The growing seems to be working fine but the shrinking function is acting very strange. By strange I mean, in Chrome it will repeatedly shrink and grow over and over. It's all pretty weird. You can view the way it's working here. I'd love any input. Code: <script type="text/javascript"> function grow1(targetid){ set_zindex = document.getElementById(targetid).style.zIndex="1"; thewidth=document.getElementById(targetid).offsetWidth; if(thewidth<940){ document.getElementById(targetid).style.width=thewidth+10+'px'; } else if(thewidth>=940){ clearInterval(change); } change=setInterval("grow1('div1')",15); } function shrink1(targetid){ thewidth2=document.getElementById(targetid).offsetWidth; if(thewidth2>290){ document.getElementById(targetid).style.width=thewidth2-10+'px'; } else if(thewidth2<=290){ clearInterval(change2); } change2=setInterval("shrink1('div1')",15); } </script> I already asked that question on Stack Overflow, however so far I haven't gotten any answers there, so I thought maybe somebody here could help me. Below is the question, copied from Stack Overflow. I've got this problem that I've been trying to solve for a week and I'm at wit's end (which, well, most likely means my wit's not so great, since it doesn't seem to be a very hard problem; nonetheless I'm very new to Javascript and am trying to look at this as a learning experience). I wanted to have a fixed position element that would rotate as a user scrolls the page. Doing so in CSS is trivially easy, however it doesn't work all that great, especially across browsers (works fine in Chrome, but is janky in Firefox) and under stress (when I turn on FPS meter or some other stuff in Chrome Developer Tools it stops working correctly ― I assume it would also behave similarly if there was another CPU-extensive app open etc.). So I figured that animating in the canvas would be a more stable technique. Doing the basic animation in the canvas is, again, rather easy. However I started having problems while trying to emulate the CSS transition effect. In short, I'm trying to emulate a code like this: Code: <!DOCTYPE html> <html> <head> <title>Page Title</title> <style> body { height: 3000px; } #square { margin: 50px; width: 150px; height: 150px; position: fixed; background-color: black; transition: transform linear 0.3s; } </style> <script> window.onload = function() { var deg = 0; var pos = window.pageYOffset; var square = document.getElementById('square'); window.onscroll = function() { var npos = window.pageYOffset; deg += (npos - pos) / 10; pos = npos; square.style.transform = 'rotate(' + deg + 'deg)'; } } </script> </head> <body> <div id='square'></div> </body> </html> And what I've got currently is below. This is, like, fifteenth try, and if you run it, you'll see that it kind of works but is very ugly and totally not how it should look. I have had better results before, but still not what I was looking for. Code: <!DOCTYPE html> <html> <head> <title>Page Title</title> <style> body { height: 3000px; } canvas { position: fixed; } </style> </head> <body> <canvas id='canvas' width='250' height='250'></canvas> <script> window.onload = function() { // some canvas geometry stuff var canvas = document.getElementById('canvas'); var c = canvas.getContext('2d'); c.translate(125,125); var deg = Math.PI / 180; // initializing variables var request = null; var deg = 0; var ndeg = 0; var base_degree; var pos = window.pageYOffset; var time = 0; var duration = 300; // in milliseconds draw(); document.addEventListener('scroll', rotateStart, false); function rotateStart() { // at the beggining of the scroll, set the time variable and start the loop. // if scroll continues, only set the time (thus resetting the animation), // but don't call loop, since it's already set as a callback to requestAnimationFrame. if (request == null) { time = (new Date()).getTime(); loop(); } else { time = (new Date()).getTime(); } } function loop() { // time passed as a fraction of total duration of animation. Describes our progress var fraction = ((new Date()).getTime() - time) / duration; if (fraction == 0) { // if current time and old time are the same, skip this frame request = window.requestAnimationFrame(loop); } else if (fraction < 1) { base_degree = (window.pageYOffset - pos) / 10; ndeg = deg + base_degree * fraction; // we operate on ndeg, and preserve deg as a reference point request = window.requestAnimationFrame(loop); draw(); } else { // clean up code. // we draw one last time at a definitive degree of rotation because // in my experience with similar scripts it sometimes doesn't go all the way there, // e.g. maybe it stops at fraction == 0.95 or something like that. ndeg = deg + base_degree; draw(); deg = ndeg; pos = window.pageYOffset; request = null; } } function draw() { c.save(); c.clearRect(-125,-125,250,250); c.rotate(ndeg * deg); c.fillRect(-75,-75,150,150); c.restore(); } }; </script> </body> </html> Could somebody point out errors in what I'm doing, post a solution, give a hint as to what method would be preferred here, whatever? Does anyone have an explanation for why animated .gifs might not animate in FF, Chrome, etc.? Only IE does it right for me. I suspect it might have something to do with tables squeezing the graphic (if the .gif is inside a table with a 100% width cell... but even giving the cell with the .gif a width doesn't seem to help.) Is it true? I realise tables are not best used for this purpose, but did this also happen in the good old tables days? Hi, I wrote a function which animates an image which looks similar to this: Quote: function animate() { var image = document.getElementById("frontImage"); var cssLeft = image.style.left; var px = cssLeft.substring(0, cssLeft.search("px")); if (px == 100) return; px++; image.style.left = px + "px"; //alert(timage.style.left); setTimeout(this.rotate(), 1); } This seems to be working fine. However, the image goes directly to its final position (100px to the right) and does not go through all the intermediate positions. As soon as I add an alert (the one which is now commented) everything works fine. Anyone knows what the problem is? Thanks in advance for any help Does anyone know a way to do vertical sync with javascript animations (getting timers to run on the vertical sync)? I rather doubt there is a way to do it, but I find it annoying that when I am dragging an object with my mouse that the object "tears" sometimes. Hello there! Brand new to the forums, but a regular reader. I'm currently in the process of putting together a site and before I get too much further I had a few Spry related questions (hope this is the correct forum for such questions). Please bear with me if my questions seem plentiful or ignorant. First off, here's the current progress of the site in question: http://thedeadhamster.com/testing/index.htm As you can (hopefully) see, upon the site's loading the header does some slide in animations. This animation would only animate on the home page; all linked pages would have a static header. While I think it looks rather nice I'm actually hesitant to use it. Here's a few of my concerns, perhaps some of you know of some possible solutions: I can't seem to get the images to animate when they're just div backgrounds. As such, I'm using image tags to make up the header which unfortunately adds the images into the HTML structure itself and doesn't really seem "good practice". Or am I simply missing something? The images sometimes "flash" on screen prior to animating, a result of the browser loading the images before the Spry coding I assume. Any simple workaround to that? Should I just forget animating the header and settle for a static background image header instead? Aka, is this more trouble than it's worth? Any thoughts or suggestions are most welcome, I appreciate any help you guys graciously throw my way. Thanks! Code: $(document).ready(function(){ $("#logo,#menu").hover( function () { $("#menu").stop().slideDown('fast'); }, function () { $("#menu").stop().slideUp('slow'); } ); }); This menu slides down on hover and slides up on un hover. If I mouse back on either object while slideUp() is happening, the animation stops. Then if i un hover / re-hover , the menu slides down to where i interrupted the initial slideUp(). I'd like for the menu to drop back down if I interrupt slideUp() or some type of solution. How can I do this? So I have a navigation thats decently simple, but the JS doesnt seem to operate in the correct manner. When i hover over a child navigation list item, the parent will start its animation as well. I know when you hover over the child you are in turn hovering over the parent, but is there a way to get the parent to not animate? http://jsfiddle.net/bWRWt/ This is an example we can all work on, which is exactly my situation. Hi, I currently created a video uploader, but when the video is too big in size, the page seems to be not doing any until the video is completely uploaded. I want to put somewhat like "loading.. please wait" script until the video is not completely uploaded. Thanks. //Ana This is a simple basic game i want to make. Its a "What Am I" Riddle... The questions is (In HTML which i already know): I'm as light as a feather but no man can hold me for long. What am I? the answer is: Your Breath. (This is where the JAVASCRIPT comes in) Lets say they guess a rock, have a pop up say: Wrong Answer. Please try again. Lets say they guess Your breath -OR- Breath, have a pop up say: Correct! I want a text field where you can enter your answer, and if they choose ANYTHING but the 2 correct answers above, it will display please try again. Can anyone code this please? Thanks for reading. Ok so i want to work on an EASY basic game. As simple as Guess what number... But there are some twist... Ok So here is my example... (HTML, i know this.)I'm Guessing a number 1-99. What is it? (java) Lets say its 66 and they guess 53, have the text rusult be in a pop up window be: Too low! (java) Lets say they guess 78, have the text rusult be in a pop up window be: Too high! (java) Lets say they guess 100+, have the text rusult be in a pop up window be: Out of range! (java)But lets say they guess 66, have a text result be in a pop up window be: You've won! (java) I want a text field where you can enter your answer, and it will do the actions above. Can anyone code this? Thanks for reading! hi guys, i was wondering if anyone could help me. Ive been looking into the above and want to implement it on my site. I have created no flash pages and flash pages, but instead of creating a portal at the front of the site that leads you to a flash site and a no flash site id like to do it so the page detects flash or not, and redirects to whichever URL. Is this possible, or do multiple browsers cause problems ? cheers |