1

Im trying to do sprite animation in p5.

let spritesheet;

function setup() {
    createCanvas(innerWidth, innerHeight);
    spritesheet = loadImage('./spritesheet.png')
    background(0)
}

function draw() {
    let img = spritesheet.get(0, 0, 100, 100)
    console.log(img)
    image(img,0,0,100,100)
}

When the y is 0

let img = spritesheet.get(0, 0, 100, 100)

It works fine but when I try to adjust values of z or y it breaks

let img = spritesheet.get(0, 100, 100, 100)

Here is the console log

console errror

Valentin Vignal
  • 6,151
  • 2
  • 33
  • 73
  • 1
    Welcome to Stack Overflow! Please take the [tour], have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) *"Here is the console log"* Please post code, error messages, markup, and other textual information **as text**, not as a *picture* of text. Why: http://meta.stackoverflow.com/q/285551/157247 – T.J. Crowder Oct 31 '21 at 11:11
  • 1
    Thanks Ill take care of that.. I thought it would be awful to see those big errors without colors. But you guys are pro... btw is there any other EASY way to get xps. I cant even upvote an answer. And answering questions are too tough for my tiny brain :( – Shreyansh Shrivastva Oct 31 '21 at 15:44
  • 1
    You're on the right track, but a few things look a bit funny. It would be good if you could post spritesheet.png. What are the dimensions of spritesheet.png. Shouldn't the image be loaded in [`preload()`](https://p5js.org/reference/#/p5/preload). Are you using a [local web server](https://github.com/processing/p5.js/wiki/Local-server) ? If it helps, I wrote [a long answer on spritesheets with p5](https://stackoverflow.com/questions/55556823/how-do-you-work-with-sprites-and-why-were-they-used-so-widely-in-older-games/55559855#55559855), but more than happy to answer your specific question too. – George Profenza Oct 31 '21 at 20:26
  • 1
    Please provide your spridesheet.png or it's dimensions. It looks to me like your image.get() function is getting out of the range of the spritesheet. – KamielDev Nov 01 '21 at 18:11

0 Answers0