Skip to content

Instantly share code, notes, and snippets.

@corpsefilth
corpsefilth / sampleState.js
Last active August 29, 2015 14:15
What is a state? Phaser State sample structure
// Create one state called 'sampleState'
var sampleState = {
// Define all the functions of the state
preload: function() {
// This function will be executed at the beginning
// That's where we load the game's assets
},
create: function() {
// This function is called after the preload function
// Here we set up the game, display sprites, etc.
@corpsefilth
corpsefilth / groupInfo.js
Created February 16, 2015 08:01
More info on Phaser groups
// A group can act like a giant sprite, so it has the same properties you can edit
group.x;
group.y;
group.alpha;
group.angle;
// Return the number of living members in the group
group.countLiving();
@corpsefilth
corpsefilth / spriteInfo.js
Created February 16, 2015 08:08
Phaser Sprite reference
// Create a local variable
var someSprite = game.add.sprite(250, 170, 'someSprite');
// Create a state variable
this.someSprite = game.add.sprite(250, 170, 'someSprite');
// using predefined pos
this.someSprite = game.add.sprite(game.world.centerX, game.world.centerY, 'someSprite');
// Set the anchor point to the top left of the sprite (default value)
@corpsefilth
corpsefilth / audioInfo.js
Created February 21, 2015 02:04
Loading music assets. Phaser
// Load the music in 2 different formats, in the preload function
game.load.audio('music', ['assets/music.ogg', 'assets/music.mp3']);
// Add and start the music in the 'create' function
// Because we want to play the music when the play state starts
this.music = game.add.audio('music'); // Add the music
this.music.loop = true; // Make it loop
this.music.play(); // Start the music
// And don't forget to stop the music in the 'playerDie' function
@corpsefilth
corpsefilth / tweenInfo.js
Last active August 29, 2015 14:15
Tween information. Phaser
// Create a tween on the label
var tween = game.add.tween(nameLabel);
// Change the y position of the label to 80, in 1000 ms
tween.to({y: 80}, 1000);
// Start the tween
tween.start();
game.add.tween(nameLabel).to({y: 80}, 1000).start();
game.add.tween(nameLabel).to({y: 80}, 1000).easing(Phaser.Easing.Bounce.Out).start();
@corpsefilth
corpsefilth / menucloner.js
Created March 12, 2015 10:09
Create a clone of your menu -- sticky menu
// Create a clone of the menu, right next to original.
jQuery('.header')
.addClass('original')
.clone().insertAfter('.header')
.addClass('cloned')
.css('position','fixed')
.css('top','0')
.css('margin-top','0')
.css('z-index','500')
.removeClass('original')
@corpsefilth
corpsefilth / CategoryCustomField.php
Created March 16, 2015 11:49
Quick hack, make sure to run only once, paste at header of theme file. Adds custom field to category. Magento.
<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute = array(
'type' => 'text',
'label'=> 'Custom Title',
'input' => 'textarea',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
@corpsefilth
corpsefilth / .htaccess
Created March 16, 2015 12:12
Rewrite all index.php out of url on front end but not backend in magento, add this to .htaccess file
## rewrite everything else to index.php
RewriteRule .* index.php [L]
RewriteCond %{REQUEST_URI} !^/index.php/admin/
RewriteCond %{REQUEST_URI} !^/index.php/admin
RewriteRule ^index.php/(.*) /$1 [R=301,QSA,L]
@corpsefilth
corpsefilth / spConfigIndex.js
Created April 16, 2015 02:14
configurable swatches magento 1.9.1, make first option selected by default -- BETA -- not for production, you will need to make slight mods.
function fireEvent(element,event)
{
if (document.createEventObject)
{
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt);
}
else
{
@corpsefilth
corpsefilth / dropdownSelect.php
Created April 16, 2015 02:16
Configurable products, make first dropdown option selected by default -- does not work with configurable swatches, only default configurable dropdown.
<script>
//we create new function
spConfig.setInitialState = function(dropdown_id) {
//select dropdown
var dropdown = $(dropdown_id);
//remove empty option from dropdown so it is not selectable after initial selection