update: function(dt) { // check entity collision var res = me.game.world.collide(this); // check & update player movement this.updateMovement(); ... },The key is to make sure you have the me.game.world.collide(this) call.
Adventures in all things programming
Saturday, April 26, 2014
MelonJS collision with entities not working
I recently started playing around with MelonJS to create a simple platformer game. Quickly I ran into an issue where my character was not colliding with other entities. The strange this is that the character was respecting the solid objects specified in the collision layer of the TMX map. This lead to several problems like not being able to pick up coins and being unable to change to the next level. The problem turned out to be that in the player's update method, I was not telling the game engine to process these types of collisions.
Wednesday, February 26, 2014
Tortoise SVN log merge multiple revision diffs
If you are doing a review, it can often be hard to see what was changed across multiple commits. Sometimes the same file is edited multiple times and you want to see what the difference between the initial and the final revisions are instead of trying to mentally add up all of the changes. If you are using Tortoise SVN, this is very easy and intuitive. To see a unified diff between multiple revisions, open the GUI Tortoise SVN log client. Then simply select multiple revisions by holding shift or ctrl and all the work is done for you. The bottom most pane will have the unified diff of all the revisions that were selected!
Tuesday, February 25, 2014
Word 2013 Cookies Must Be Enabled
I came across an issue where I was not able to sign in to SkyDrive/OneDrive with my Microsoft account with Word 2013. I constantly came across a popup that told me that "Cookies Must Be Enabled". Some simple searching showed that a possible solution was to set Privacy settings to Low in Internet Explorer. This did not fix the issue for me. However, to fix it I ended up allowing cookies from microsoft.com and live.com. To do this go to Sites and type in those two sites to allow.
Wednesday, February 19, 2014
Ant execute actions based on if else conditions for an environment variable
Sometimes you may need to take different actions during your Java application build process depending on if an environment variable is set. A scenario that I came across is that if a particular environment variable was set, then files needed to be copied from one location, otherwise from another. Apache Ant is not meant to be a programming language so it is often difficult to accomplish tasks like this. However, I found a way to do this by creating two sub-targets for each boolean value of a conditional. Each target is conditionally executed by using if and unless attributes which check the property if the environment variable VARIABLE was set.
<property environment="env"/> <condition property="exists.envVar"> <isset property="env.VARIABLE"/> </condition> <target name="task" depends="-task-true, -task-false"/> <target name="-task-true" if="exists.envVar"> <echo>Execute something here</echo> </target> <target name="-task-false" unless="exists.envVar"> <echo>Or execute this instead</echo> </target>The sub-targets are prepended with - character and are missing documentation attribute so that they cannot be executed from the command line. The user calls the main target (task in this example), and the logic does the rest.
Friday, December 13, 2013
SVN log changes between revisions
Normally the svn log command lists revisions from the most recent revision to the beginning of time. It's possible to only list a log between a range of revisions using the following syntax:
-v gives verbose output, showing the files changed
--stop-on-copy only lists history for that branch, instead of following branch instructions and looking at the parent's history
-r lets you specify the revision, or in this case the range with the : operator
This will give you the history for revisions 250-1000 inclusive.
svn log https://server.com/svn/product -v --stop-on-copy -r 250:1000
-v gives verbose output, showing the files changed
--stop-on-copy only lists history for that branch, instead of following branch instructions and looking at the parent's history
-r lets you specify the revision, or in this case the range with the : operator
This will give you the history for revisions 250-1000 inclusive.
Monday, November 18, 2013
Set Git to not prompt for a password
Writing scripts to work with Git repositories will quickly lead you to a problem -- the interactive password prompt. The best way to make a script that doesn't ask for a password on git push or pull is to use SSH keys. However, sometimes that is not possible because an administrator has not enabled SSH key on the server for example. Another quick and dirty solution is to place the credentials into your .netrc file.
Now, you will have to edit the .netrc file. It is located in the user's home directory (~./netrc). Here, you will have to add an entry of the form:
And that's it! It should be noted that this is not a very secure method. Anybody with access to that file will have your git user's password.
To do this, you will have to make sure that the remote URL doesn't contain the username. To see the current remotes run:
git remote
The new URL cannot have a username in it (user@server.com...). To update a URL, run:
git remote set-url origin https://server.company.com/path/to/repo.git
machine server.company.com login username password password
And that's it! It should be noted that this is not a very secure method. Anybody with access to that file will have your git user's password.
Tuesday, October 29, 2013
Waiting on font load for HTML5 canvas using Web Font Loader
A very common problem is how to preload a font before running your canvas application. You will easily find out that you have this problem in your hands if text suddenly appears, or starts out as a different font (Flash Of Unstyled Font). One way to fix this issue is to use Google Web Font Loader. There are many tutorials on how to do with with web fonts, but not many with local fonts (your own fonts that you are serving). Here is an example with a simple application:
Let's assume you have some fonts that you want to use for your application, stored under fonts/ directory. Your CSS file fonts.css will look something like this:
You will not need to make any changes to that file. Your html file may have looked something like this:
You will have to change the html file to not load immediately because the issue arises from the browser's asynchronous loading of the font. This means that the font may not be ready when your javascript code finally runs. To call the myMain function only when the fonts load, we will use Google Web Font Loader. This way, the font will be pre-loaded and we can use that font in the canvas.
To do that, all you have to do is remove your call from the body's onload and add it to the activate callback from the WebFontConfig:
Make sure to put the two scripts in that order! This is important because you must first create the WebFontConfig object which the webfont.js script will look for. Putting it all together, your html file will look like this:
Let's assume you have some fonts that you want to use for your application, stored under fonts/ directory. Your CSS file fonts.css will look something like this:
@font-face { font-family: "digital"; src: url('fonts/digital-7 (mono).ttf'); }
You will not need to make any changes to that file. Your html file may have looked something like this:
<body onload="myMain()"> <canvas id="mainCanvas" width="600" height="600"></canvas> </body>
You will have to change the html file to not load immediately because the issue arises from the browser's asynchronous loading of the font. This means that the font may not be ready when your javascript code finally runs. To call the myMain function only when the fonts load, we will use Google Web Font Loader. This way, the font will be pre-loaded and we can use that font in the canvas.
To do that, all you have to do is remove your call from the body's onload and add it to the activate callback from the WebFontConfig:
<script> // load fonts before loading the game WebFontConfig = { custom: { families: ['digital'], urls: ['fonts.css'] }, active: function() { myMain(); } }; </script> <script src="//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js"></script>
Make sure to put the two scripts in that order! This is important because you must first create the WebFontConfig object which the webfont.js script will look for. Putting it all together, your html file will look like this:
<!DOCTYPE html> <html lang="en-us"> <head> <meta charset="utf-8"> <title>HTML 5 WebApp</title> <script src="snake.js"></script> <script> // load fonts before loading the game WebFontConfig = { custom: { families: ['digital'], urls: ['fonts.css'] }, active: function() { myMain(); } }; </script> <script src="//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js"></script> </head> <body> <canvas id="mainCanvas" width="600" height="600"></canvas> </body> </html>
Subscribe to:
Posts (Atom)