bobcgausa/cook-js

cannot use correct size of backgroundImage

Closed this issue · 3 comments

hello,i want to ask a question. when i add the lib to draw a fountain, i found the size of my backgroundImage is incorrect. Before using the lib, it can show normally.Here is my code:

var backgroundImg;
var defs;
var of;

function setup() {
	createCanvas(windowWidth, windowHeight);
  	backgroundImg = loadImage("assets/background.jpg");
	var t =
        '{   ' +
        '    "parts": [   ' +
        '    {   ' +
        '    "name": "foo",   ' +
        '    "color":   ' +
        '     ["orange",[255,0,0],"yellow","white","white"],   ' +
        '    "gravity": 0.1,   ' +
        '    "sizePercent": 0.99,   ' +
        '    "angle": [170,350],   ' +
        '    "speed": 5.5,   ' +
        '    "limit": 250,   ' +
        '    "lifetime": 200,   ' +
        '    "size": [4,12],   ' +
        '    "x": 0.5,   ' +
        '    "y": 0.5}]}';

    defs = JSON.parse(t);
    of = new Fountain(defs, 'foo');
}

function draw() {
	clear();
	background(backgroundImg);
	of.Draw();
  	of.Create();
  	of.Step(); 	
  	noStroke();
  	text(of.length, width/2, 20);
  	stroke(0);
}

like this:
screenshot

Thanks for your reply. But it still cannot show correctly and using Image(img,0,0,width,height) instead, the img will hide the fountain.

var t =
        '{   '
        ......
        '    "x": 0.5,   ' +
        '    "y": 0.5}]}';

i noticed that the coordinate has been changed. Will it be related to this issue?