Except in the example I do not use Crafty.mobile. The fullscreen is triggered because the Note's browser resolution is less than 960 pixels. The screen resolution is higher than 960, but the browser's is not.
Prabhakar - start another thread about your questions regarding full screen mode and crafty.mobile. Thanks!
Description:
This fiddle illustrates one way of loading a large (1280x1280) background image for a game world.
The player can be moved around using the up, down, left, and right arrow keys, in increments of 32 pixels.
The Crafty viewport follows the player, and the stage is 500x500 pixels. There is no collision detection, but you could extend this to use Crafty's collision detection.
The fiddle requests sprites from the OpenGameArt.org website, which is a great resource for sprites to use in your own game.
I've adopted this approach for a game that I am working on. I found that having a small viewport with a scrolling background works well on mobile devices, due to limited screen space.
Fiddle:
http://jsfiddle.net/FpNaF/
Crafty.e("2D, Canvas, Tween, Color").attr({alpha:0.0, x:0, y:0, w:800, h:600}).color("#000000").tween({alpha: 1.0}, duration).bind("TweenEnd", function() {Crafty.scene(scene);Crafty.e("2D, Canvas, Tween, Color").attr({alpha:1.0, x:0, y:0, w:800, h:600}).color("#000000").tween({alpha: 0.0}, duration);});}
I'd like to start a community cookbook, where everyone can contribute code that they have found to be useful in some way.
In return, everyone can study the code and together we can build a cookbook for Crafty.
For consistency, I'd like the examples to follow a basic pattern:
A description of what your code does, any wisdom you gained from using it, and a link to a jsfiddle illustrating your code. I will start:
Description:
This snippet will initialize the Crafty viewport to fullscreen, up to a maximum size you specify.
I've set the maximum width at 960 in the example.
I've found that the iPhone 3g, 3gs, and 4g will trigger full screen mode, implying a lower resolution than 960 pixels wide (as of 7/2012).
I've also discovered that the Samsung Note will trigger full screen mode as well.
Fiddle:
http://jsfiddle.net/ysDtQ/1/
I will try to keep the momentum going by posting snippets daily.
Feel free to contribute examples, but I'd prefer to keep the questions regarding examples in a new thread specific to that question.
Thanks,
//garrick
Description:
Fiddle1 shows example when player has collision component and obstacle doesnt. Obstacle is working, so player cannot go trough BUT it doesnt take player polygon but the sprite into collision.
Fiddle1:
http://jsfiddle.net/qY5k2/1/
Fiddle2:
http://jsfiddle.net/qY5k2/2/
--
You received this message because you are subscribed to the Google Groups "Crafty" group.
To unsubscribe from this group and stop receiving emails from it, send an email to craftyjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Crafty" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/craftyjs/qtUQaDzVYAM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to craftyjs+u...@googlegroups.com.
Description:
Cobbled together from examples around the web, here is a simple and effective (and probably incorrect) way to get a sprite animated and moving with controls. Make no mistake, it's ugly in every respect from, but it represents a javascript learning experience and it works!
Also, I scoured the web for code to deconstruct and found very little. I can't believe I didn't just check this forum for code examples, it would have made this a lot easier.
Crafty.c('MovingEntity',
{
spriteName:'',
init: function()
{
this.requires('Entity, Collision, SpriteAnimation, Sprite')
.collision(new Crafty.polygon(0, 0, 0, 32, 32, 32, 0, 32))
.bind('HitOn', this.onHitOn)
.bind('HitOff', this.onHitOff)
.bind('Moved', this.onMove)
;
},
onHitOn: function()
{
return this;
},
onHitOff: function()
{
return this;
},
onMove: function()
{
return this;
}
});
Crafty.c('Living',
{
health:0,
init: function()
{
},
getHealth: function()
{
return health;
},
modifyHealth: function(modHealth)
{
this.health = this.health-modHealth;
return this;
}
});