I'm trying to use cocos2d-js to make a canvas webgame that uses pixel graphics.
I have made the canvas and the setDesignResolutionsize to be the size of the viewport.
I can't make a sprite that isn't antialiased. I have tried using
sprite.getTexture().setAliasTexParameters();
Although I may be using it wrong.
var canvas = document.getElementById("gameCanvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
cc.game.onStart = function(){
//load resources
cc.view.setDesignResolutionSize(canvas.width, canvas.height, cc.ResolutionPolicy.SHOW_ALL);
cc.LoaderScene.preload(gameResources, function () {
cc.director.runScene(new MyScene());
}, this);
};
cc.game.run("gameCanvas");
var MyScene = cc.Scene.extend({
onEnter:function () {
this._super();
var gameLayer = new game();
gameLayer.init();
this.addChild(gameLayer);
}
});
var backgroundLayer;
var game = cc.Layer.extend({
init:function() {
this._super();
var sprite = cc.Sprite.create("assets/ui/title.png");
sprite.getTexture().setAliasTexParameters();
this.addChild(sprite,0);
sprite.setPosition((window.innerWidth/2),(window.innerHeight/2));
}
});
This is the results with png for comparison:
foreground: title png image, background: rendered sprite
Who can help?