Giter Club home page Giter Club logo

cax's Introduction

English | 简体中文

Cax

Canvas 2D Rendering Engine

Features

  • Simple API, Lightweight and High performance
  • Support PC and Mobile Canvas 2D Rendering and Mouse and Touch Event
  • Support event of element and element management like DOM
  • Turing complete group nesting system
  • Support clip and clip transformation
  • Built-in Text, Bitmap, Sprite, Graphics and Shape
  • Support SVG Path rendering
  • Support CSS filter
  • Built-in images loader
  • Built-in cross platform motion library → to2to

Demo

→ Demo Source Code

Docs

Getting Started

Get cax through npm or cdn:

npm i cax

Usage:

import cax from 'cax'

const stage = new cax.Stage(200, 200, 'body')

cax.loadImgs({
  imgs: ['./test.jpg'],
  complete: (imgs) => {
    const img = imgs[0]
    const bitmap = new cax.Bitmap(img)

    bitmap.x = stage.width / 2
    bitmap.y = stage.height / 2
    bitmap.rotation = -10
    bitmap.originX = img.width / 2
    bitmap.originY = img.height / 2
    bitmap.filter('blur(10px)')

    stage.add(bitmap)
    stage.update()
  }
})

Built-in Object

Group

For grouping, group can also nested group, and the parent container's properties will be superimposed on child properties, such as:

  • the x of group is 100, the x of bitmap in group is 200, and the x of the bitmap rendered to stage is 300.
  • the alpha of group is 0.7, the alpha of bitmap in group is 0.6, and the alpha of the bitmap rendered to stage is 0.42.
const group = new cax.Group()
const rect = new cax.Rect(100, 100, {
  fillStyle: 'black'
})
group.add(rect)
stage.add(group)
stage.update()

Group has commonly used add and remove methods to add and delete elements. The first add will be drawn first, and all subsequent add will be covered above the top add.

Group Method

add

add child to group

groupObj.add(child) 
remove

remove child from group

groupObj.remove(child)
empty

remove all the children from group

groupObj.empty()
replace

replace child by another obj

groupObj.replace(current, prev)

Stage

Stage is the largest top container inherited from Group, so have all the methods and props of Group.

Stage Method

update

Any element can't be seen on the stage. You must execute the update method.

stage.update()

Any element property is modified. Please perform stage.update() to update the stage, or put it in the timer.

cax.tick(stage.update.bind(stage))
scaleEventPoint

When the height of the canvas and the pixels of the canvas are not one-to-one, the event triggering position is inaccurate, and you can use the scaleEventPoint method to make the event correct.

//The width of the canvas is half the canvas pixel
stage.scaleEventPoint(0.5, 0.5)

Example: https://github.com/dntzhang/cax/blob/master/packages/cax/examples/pie/main.js#L218-L220

Stage Prop

disableMoveDetection

Disable event detection for mouse or touch mobile. Default value in the web is false. You can change it:

stage.disableMoveDetection = true
moveDetectionInterval

Set the touchmove and mousemove detection interval by moveDetectionInterval.

//check twice in one second
stage.moveDetectionInterval = 500

Bitmap

const bitmap = new cax.Bitmap(img)
stage.add(bitmap)
stage.update()

If you only transmit URL instead of the instance of the Image object, you need to do this:

const bitmap = new cax.Bitmap('./wepay.png', ()=>{
  stage.update()
})
stage.add(bitmap)

bitmap-prop

rect

You can set the picture clipping display area, and other transform attributes:

bitmap.rect = [0, 0, 170, 140]
bitmap.x = 200
bitmap.rotation = 30

Sprite

The sequence frame animation component can combine any region of any picture into a series of animations.

const sprite = new cax.Sprite({
    framerate: 7,
    imgs: ['./mario-sheet.png'],
    frames: [
        // x, y, width, height, originX, originY ,imageIndex
        [0, 0, 32, 32],
        [32 * 1, 0, 32, 32],
        [32 * 2, 0, 32, 32],
        [32 * 3, 0, 32, 32],
        [32 * 4, 0, 32, 32],
        [32 * 5, 0, 32, 32],
        [32 * 6, 0, 32, 32],
        [32 * 7, 0, 32, 32],
        [32 * 8, 0, 32, 32],
        [32 * 9, 0, 32, 32],
        [32 * 10, 0, 32, 32],
        [32 * 11, 0, 32, 32],
        [32 * 12, 0, 32, 32],
        [32 * 13, 0, 32, 32],
        [32 * 14, 0, 32, 32]
    ],
    animations: {
        walk: {
            frames: [0, 1]
        },
        happy: {
            frames: [5, 6, 7, 8, 9]
        },
        win: {
            frames: [12]
        }
    },
    playOnce: false,
    currentAnimation: "walk",
    animationEnd: function () {

    }
});

Sprite Method

gotoAndPlay

Jump to the current animationName and start playing

spriteObj.gotoAndPlay(animationName)
gotoAndStop

Jump to the current animationName and stop

spriteObj.gotoAndStop(animationName)
gotoAndPlayOnce

Jump to the current animationName and start playing, then destroy yourself after animation. Often used in explosions

spriteObj.gotoAndPlayOnce(animationName)

Text

Text object

const text = new cax.Text('Hello World', {
  font: '20px Arial',
  color: '#ff7700',
  baseline: 'top'
})

Method

getWidth

Get text width

textObj.getWidth()

Graphics

The drawing object is used to draw graphics with Canvas instructions in the basic way of linking.

const graphics = new cax.Graphics()
graphics
    .beginPath()
    .arc(0, 0, 10, 0, Math.PI * 2)
    .closePath()
    .fillStyle('#f4862c')
    .fill()
    .strokeStyle('black')
    .stroke()

graphics.x = 100
graphics.y = 200

stage.add(graphics)

In particular, if you perform a graphics connection rendering operation in a loop, be sure to add the clear () method, or the path will be overloaded to your browser:

cax.setInterval(function(){
  graphics
    .clear()
    .beginPath()
    .arc(0, 0, 10, 0, Math.PI * 2)
    .stroke()
}, 16)

Shape

Unlike Graphics, Shape usually has limited width height, so it can be buffered with off screen Canvas. The following are Shape.

Rect

const rect = new cax.Rect(200, 100, {
  fillStyle: 'black'
})

Circle

const circle = new cax.Circle(10)

Ellipse

const ellipse = new cax.Ellipse(120, 20)

Element

Element is a combination of multiple elements, such as Bitmap, Group, Text, Shape and other mixed images.

Button

const button = new cax.Button({
  width: 100,
  height: 40,
  text: "Click Me!"
})

Property

Transform

name Describe
x Horizontal offset
y Vertical offset
scaleX Horizontal scaling
scaleY Vertical scaling
scale Horizontal and Vertical scaling
rotation rotation
skewX skewX
skewY skewY
originX Rotation base point X
originY Rotation base point Y

Alpha

Name Describe
alpha The transparency of the element

Notice that the father and son have set up alpha to do multiplicative stacking.

compositeOperation

Name Describe
compositeOperation The superposition pattern drawn from the source image to the target image

Notice that if you don't have a definition of compositeOperation to look up, find the nearest compositeOperation's parent container as its own compositeOperation.

Cursor

Name Describe
cursor The shape of the mouse

Fixed

Name Describe
fixed Whether to fixed or not, the default is false, and set to true will not overlay the transform of ancestors.

Shadow

Name Describe
shadow shadow

Usage:

obj.shadow = {
    color: '#42B035',
    offsetX: -5,
    offsetY: 5,
    blur: 10
}

Stage

Name Describe
stage get the root stage

Usage:

obj.stage

Method

destroy

Destroy self

obj.destroy()

Event

Name Describe
click Click time trigger on the element
mousedown Triggers when the mouse button is pressed on the element
mousemove Trigger when the mouse pointer moves to the element
mouseup Trigger when the mouse button is released on the element
mouseover Trigger when the mouse pointer moves to the element
mouseout Trigger when the mouse pointer moves out of the element
tap Leave the finger and leave immediately
touchstart The start of finger touch action
touchmove Move the finger after touch
touchend End of finger touch action
drag Drag and drop
const handler = () => {}
obj.on('click', handler)

//unbind
obj.off('click', handler)

Motion

Cax has built-in to capability to write motion effects in a continuous way.

const easing = cax.To.easing.elasticInOut

cax.To.get(bitmap)
    .to({ y: 340, rotation: 240 }, 2000, easing)
    .begin(() => {
        console.log("Task one has began!")
    })
    .progress(() => {
        console.log("Task one is progressing!")
    })
    .end(() => {
        console.log("Task one has completed!")
    })
    .wait(500)
    .to()
    .rotation(0, 1400, easing)
    .begin(() => {
        console.log("Task two has began!")
    })
    .progress(() => {
        console.log("Task two is progressing!")
    })
    .end(() => {
        console.log("Task two has completed!")
    })
    .start();
  • to and to are parallel
  • to and wait are serial
  • The serial between to and to is serial with the next to and to

If you want circular motion, you can use the cycle method:

cax.To.get(bitmap)
    .to()
    .y(340, 2000, cax.easing.elasticInOut)
    .to
    .y(0, 2000, cax.easing.elasticInOut)
    .cycle()
    .start()

It's important to note that, unlike tween.js, Cax uses the camelcase. For example, Cubic.In becomes cubicIn.

Clip

const stage = new cax.Stage(600, 400, 'body')
const bitmap = new cax.Bitmap('./wepay-diy.jpg', () => {
    stage.update()
})
const clipPath = new cax.Graphics()
clipPath.arc(40, 40, 25, 0, Math.PI * 2)
bitmap.clip(clipPath)
stage.add(bitmap)

You can get the same effect with blow code:

const clipPath = new cax.Graphics()
clipPath.x = 40
clipPath.y = 40
clipPath.arc(0, 0, 25, 0, Math.PI * 2)

So you can find that clip graphics supports all the transformation props(x,y,scaleX,scaleY,rotation,skewX,skewY,originX,originY).

→ Clip Demo

Custom Object

Custom Shape

Custom Shape inherits from cax.Shape:

class Sector extends cax.Shape {
  constructor (r, from, to, option) {
    super()

    this.option = option || {}
    this.r = r
    this.from = from
    this.to = to
  }

  draw () {
    this.beginPath()
      .moveTo(0, 0)
      .arc(0, 0, this.r, this.from, this.to)
      .closePath()
      .fillStyle(this.option.fillStyle)
      .fill()
      .strokeStyle(this.option.strokeStyle)
      .lineWidth(this.option.lineWidth)
      .stroke()
  }
}

Use the Shape:

const sector = new Sector(10, 0, Math.PI/6, {
  fillStyle: 'red'
  lineWidth: 2
})
stage.add(sector)
stage.update()

Custom Element

Custom Element inherits from cax.Group:

class Button extends cax.Group {
  constructor (option) {
    super()
    this.width = option.width
    this.roundedRect = new  cax.RoundedRect(option.width, option.height, option.r)
    this.text = new cax.Text(option.text, {
      font: option.font,
      color: option.color
    })

    this.text.x = option.width / 2 - this.text.getWidth() / 2 * this.text.scaleX
    this.text.y = option.height / 2 - 10 + 5 * this.text.scaleY
    this.add(this.roundedRect, this.text)
  }
}

export default Button

Use the Button:

const button = new cax.Button({
  width: 100,
  height: 40,
  text: "Click Me!"
})

In general, it is suggested that inherit Group from a slightly complex combination, which is conducive to expansion and management of internal components.

Wechat Game Demo

你在画什么

点十消除

License

MIT

cax's People

Contributors

ashton00 avatar bryant1410 avatar dntzhang avatar dwqdaiwenqi avatar eroszy avatar inarol avatar kinvix avatar pepsin avatar winggao avatar zacksleo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cax's Issues

小程序redirectTo切换页面第二次不显示

使用redirectTo在两个页面中来回切换
A页面有canvas,onLoad中做的初始化和渲染。
B页面没有canvas。
进入小程序先进入B页面,再redirectTo到A页面,这个时候A页面的canvas是有渲染有显示的。
再从A页面redirectTo到B页面,再redirectTo到A页面,这个时候A页面的canvas是就没有显示了。
我在onUnload中销毁了我创建的Stage,Group以及Bitmap仍然没有显示。
将初始化和渲染写在onReady中,第二次redirectTo到A页面也没有任何显示。

求解,拜托了。

当前最新代码的事件绑定失效

当前Master分支中的代码绑定事件不会触发到,麻烦库主尽快修复。另几个Demo希望更新,由于使用了ARE代替原are全局变量,好几个demo跑不起来。若可以,整理一份API文档就更好了,没有API文档,都不知道有什么API,只能边写边看源码,效率低下。

bitmap 裁剪有明显锯齿

const icon = new cax.Bitmap(src)
const clipPath = new cax.Graphics()
clipPath.arc(ICON_SIZE, ICON_SIZE, ICON_SIZE, 0, Math.PI * 2)
icon.clip(clipPath)

我用如上代码裁剪一个bitmap,结果能看见图片周边清晰的锯齿,有什么办法解决吗?

Y29uc29sZS5sb2coJ0hhcHB5IEJpcnRoZGF5Jyk=

゚ω゚ノ= /`m´)ノ ~┻━┻ //*´∇`*/ ['_']; o=(゚ー゚) =_=3; c=(゚Θ゚) =(゚ー゚)-(゚ー゚); (゚Д゚) =(゚Θ゚)= (o^_^o)/ (o^_^o);(゚Д゚)={゚Θ゚: '_' ,゚ω゚ノ : ((゚ω゚ノ==3) +'_') [゚Θ゚] ,゚ー゚ノ :(゚ω゚ノ+ '_')[o^_^o -(゚Θ゚)] ,゚Д゚ノ:((゚ー゚==3) +'_')[゚ー゚] }; (゚Д゚) [゚Θ゚] =((゚ω゚ノ==3) +'_') [c^_^o];(゚Д゚) ['c'] = ((゚Д゚)+'_') [ (゚ー゚)+(゚ー゚)-(゚Θ゚) ];(゚Д゚) ['o'] = ((゚Д゚)+'_') [゚Θ゚];(゚o゚)=(゚Д゚) ['c']+(゚Д゚) ['o']+(゚ω゚ノ +'_')[゚Θ゚]+ ((゚ω゚ノ==3) +'_') [゚ー゚] + ((゚Д゚) +'_') [(゚ー゚)+(゚ー゚)]+ ((゚ー゚==3) +'_') [゚Θ゚]+((゚ー゚==3) +'_') [(゚ー゚) - (゚Θ゚)]+(゚Д゚) ['c']+((゚Д゚)+'_') [(゚ー゚)+(゚ー゚)]+ (゚Д゚) ['o']+((゚ー゚==3) +'_') [゚Θ゚];(゚Д゚) ['_'] =(o^_^o) [゚o゚] [゚o゚];(゚ε゚)=((゚ー゚==3) +'_') [゚Θ゚]+ (゚Д゚) .゚Д゚ノ+((゚Д゚)+'_') [(゚ー゚) + (゚ー゚)]+((゚ー゚==3) +'_') [o^_^o -゚Θ゚]+((゚ー゚==3) +'_') [゚Θ゚]+ (゚ω゚ノ +'_') [゚Θ゚]; (゚ー゚)+=(゚Θ゚); (゚Д゚)[゚ε゚]='\\'; (゚Д゚).゚Θ゚ノ=(゚Д゚+ ゚ー゚)[o^_^o -(゚Θ゚)];(o゚ー゚o)=(゚ω゚ノ +'_')[c^_^o];(゚Д゚) [゚o゚]='\"';(゚Д゚) ['_'] ( (゚Д゚) ['_'] (゚ε゚+(゚Д゚)[゚o゚]+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (o^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ ((o^_^o) +(o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (o^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ ((゚ー゚) + (゚Θ゚))+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ ((o^_^o) +(o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚ー゚)+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚Θ゚)+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (o^_^o))+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚ー゚)+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (c^_^o)+ ((o^_^o) - (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ ((o^_^o) - (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (o^_^o))+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚ー゚)+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (゚Θ゚)+ (゚Д゚)[゚o゚]) (゚Θ゚)) ('_');

小程序中bitmap加载后没有回调

小程序的onload方法没有回调

class Bitmap extends DisplayObject {
  constructor (img, onLoad) {
    super()
    if (typeof img === 'string') {
      if (Bitmap.cache[img]) {
        this.img = Bitmap.cache[img]
        this.rect = [0, 0, this.img.width, this.img.height]
        onLoad && onLoad.call(this)
        this.width = this.img.width
        this.height = this.img.height
      } else if (util.isWeapp) {
        util.getImageInWx(img, (result) => {
          this.img = result.img
          if (!this.rect) {
            this.rect = [0, 0, result.width, result.height]
          }
        })
      } else {

小程序Bitmap的缓存不起作用

小程序的bitmap的生成后,不会存入Bitmap.cache[]。生成内容多的时候非常的卡。
尤其是从网络读取图片的时候。

      } else if (_util2.default.isWeapp) {
        _util2.default.getImageInWx(img, function (result) {
          _this.img = result.img;
          if (!_this.rect) {
            _this.rect = [0, 0, result.width, result.height];
          }
          onLoad && onLoad.call(_this);
        });
      } else {

坐标锚点

可以设置坐标的锚点在物体的中心吗?类似pixi的anchor

是否有坐标转换功能

例如:
globalToLocal 全局stage坐标 转到 显示对象内坐标

localToGlobal 显示对象内坐标 转到 全局stage坐标

在互动过程中会比较常使用到

Loader跨域加载图片失败

使用Loader从cdn加载图片资源是提示
... No 'Access-Control-Allow-Origin' header is present on the requested ...
加载MP3资源就没问题

小程序中自定义Element 使用报错

import cax from './index'

export default class poker extends cax.Group {
constructor() {
super()
const bitmap = new cax.Bitmap('../../image/user_avatar_test.png')
bitmap.scaleX = bitmap.scaleY = 0.5
this.add(this.bitmap)
}
}

error:
Cannot set property 'parent' of undefined;at "pages/live/live" page lifeCycleMethod onLoad function
TypeError: Cannot set property 'parent' of undefined
at poker.add (http://127.0.0.1:35894/appservice/components/cax/index.js:298:35)
at new poker (http://127.0.0.1:35894/appservice/components/cax/poker.js:29:11)
at r.onLoad (http://127.0.0.1:35894/appservice/pages/live/live.js:67:17)
at r. (

RoundRect无法设置fillStyle

代码里面写死white了。

最好strokeStyle也支持下,要不每次绘制后都会有黑边。

      this.closePath();
      this.fillStyle('white');
      this.fill();

小程序的裁剪不行

// 圆的半径
		const bgWidth = 640
		const bgHeight = 758
		const radii = 120
		const imageWith = width
		const imageHeight = width
		const fontSize = 36
		const innerRadii = 46

		const stage = new Stage(bgWidth, bgHeight, 'myCanvas', this)

		const bgBitmap = new Bitmap(bgSrc)
		stage.add(bgBitmap)
		
		const headBitmap = new Bitmap(this.headerImage, () => {
			stage.update()
		})
		const clipHeadPath = new Graphics()
		clipHeadPath.arc(bgWidth/2, marginTop + radii, innerRadii, 0, 2 * Math.PI)
		headBitmap.clip(clipHeadPath)
		stage.add(headBitmap)

		stage.scale = 0.5
		stage.update()

代码如上,死活裁剪不出来,去掉clipHeadPath,图片正常显示!

小程序无法加载本地图片

如果在小程序使用下面的代码是无法加载本地图片的:

    const bitmap = new cax.Bitmap('./local.png', () => {

看了下util里面的代码,用判断是否是wxfile://开头来判断是否是网络图片,在小程序里面就走downloadfile了。

export function getImageInWx (img, callback) {
  if (img.indexOf('wxfile://') === 0) {
    wx.getImageInfo({
      src: img,
      success: (info) => {
        callback({
          img: img,
          width: info.width,
          height: info.height
        })
      }
    })

真机调试的时候会卡

你好,我用定时器创建bitmap,然后做下落动画(类似红包雨),在模拟器没问题,真机调试特别卡(机型iPhone 6S plus)

cax.To 运动求cax.easing详解

'Quadratic', 'Cubic', 'Quartic', 'Quintic', 'Sinusoidal', 'Exponential', 'Circular', 'Elastic', 'Back', 'Bounce'
和 In,Out,InOut
分别是代表什么样的动画效果?

bitmap实例的img属性不可读

遇到一个奇怪的问题,偶尔有几个bitmap实例上面属性不可读,但是console出来都能看到
image

undefined是我console的,bitmap上面的img属性

group.cache 在小程序中无法使用

if (typeof wx !== 'undefined' && wx.createCanvas) {
  _this.canvas = wx.createCanvas();
} else {
  _this.canvas = document.createElement('canvas');
}

小程序中没有wx.createCanvas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.