Merge pull request #998 from knoxHuang/master

add enableAntiAlias for CCView fireball/issues/2836
This commit is contained in:
Jare Guo
2016-08-01 20:47:28 +08:00
committed by GitHub
2 changed files with 63 additions and 0 deletions
+53
View File
@@ -150,6 +150,8 @@ var View = cc._Class.extend({
_isAdjustViewPort: true,
_targetDensityDPI: null,
_antiAliasEnabled: false,
/**
* Constructor of View
*/
@@ -181,6 +183,7 @@ var View = cc._Class.extend({
_t._rpFixedWidth = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_WIDTH);
_t._targetDensityDPI = cc.macro.DENSITYDPI_HIGH;
_t.enableAntiAlias(true);
},
// Resize helper functions
@@ -415,6 +418,56 @@ var View = cc._Class.extend({
return this._retinaEnabled;
},
/**
* !#en Whether to Enable on anti-alias
* !#zh 是否开启抗锯齿
* @method enableAntiAlias
* @param {Boolean} enabled - Enable or not anti-alias
*/
enableAntiAlias: function (enabled) {
if (this._antiAliasEnabled === enabled) {
return;
}
this._antiAliasEnabled = enabled;
if(cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
var map = cc.loader._items.map;
for (var key in map) {
var item = map[key];
var tex = item && item.content instanceof cc.Texture2D ? item.content : null;
if (tex) {
if (enabled) {
tex.setAntiAliasTexParameters();
}
else {
tex.setAliasTexParameters();
}
}
}
}
else if(cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
var ctx = cc._canvas.getContext('2d');
ctx.imageSmoothingEnabled = enabled;
ctx.mozImageSmoothingEnabled = enabled;
// refresh canvas
var dirtyRegion = cc.rendererCanvas._dirtyRegion;
if (dirtyRegion) {
var oldRegion = new cc.Region();
oldRegion.setTo(0, 0, cc.visibleRect.width, cc.visibleRect.height);
dirtyRegion.addRegion(oldRegion);
}
}
},
/**
* !#en Returns whether the current enable on anti-alias
* !#zh 返回当前是否抗锯齿
* @method isAntiAliasEnabled
* @param {Boolean}
*/
isAntiAliasEnabled: function () {
return this._antiAliasEnabled;
},
/**
* If enabled, the application will try automatically to enter full screen mode on mobile devices<br/>
* You can pass true as parameter to enable it and disable it by passing false.<br/>
+10
View File
@@ -233,6 +233,16 @@ var Texture2D = cc.Class(/** @lends cc.Texture2D# */{
self._pixelHeight = self._contentSize.height = locElement.height;
self._textureLoaded = true;
// anti-alias
if(cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
if (cc.view._antiAliasEnabled) {
self.setAntiAliasTexParameters();
}
else {
self.setAliasTexParameters();
}
}
//dispatch load event to listener.
self.emit("load");
},