Jump to content
Search Community

OSUblake last won the day on September 16 2023

OSUblake had the most liked content!

OSUblake

Moderators
  • Posts

    9,196
  • Joined

  • Last visited

  • Days Won

    708

Posts posted by OSUblake

  1. 11 minutes ago, ladlon said:

    I still need to figure out how to then use that with some form of tweening... apparently Canvas-based, since I found out today that GSAP cannot (apparently) address rotation with Canvas-based scenarios.  That's odd, as I would have thought you just do the regular GSAP rotation tween on the image, then stamp it down on the canvas (as you do with GSAP positional tweens).  So, now I'm trying to sort out non-GSAP assisted Canvas rotation tweening.

     

    Again, you can do rotation. It's just a value.

     

    See the Pen a6df91724b67db6b62dfe15c76b4c433 by osublake (@osublake) on CodePen

     

     

    Not using gsap, it would look nearly identical, except you have less control.

     

    See the Pen ab9579dcaece080b8be502ce34d8fc82 by osublake (@osublake) on CodePen

     

    • Like 3
  2. 2 minutes ago, ladlon said:

     

     

    
    const canvas = document.getElementById('canvas');
    const ctx = canvas.getContext('2d');
    
    // Non-rotated rectangle
    ctx.fillStyle = 'gray';
    ctx.fillRect(80, 60, 140, 30);
    
    // Matrix transformation
    ctx.translate(150, 75);
    ctx.rotate(Math.PI / 2);
    ctx.translate(-150, -75);
    
    // Rotated rectangle
    ctx.fillStyle = 'red';
    ctx.fillRect(80, 60, 140, 30);

     

    All the matrix/transform stuff is the same for an image. Just replace the fillStyle/fillRect calls with drawImage.

     

    • Like 1
  3. 1 minute ago, ladlon said:

    Worked, but I kept getting told I should use Canvas, so I wanted to try that out, since it would provide a more stable/predictable structure, not requiring hacks and compromises.

     

    Don't know why someone would recommend that. I would only recommend canvas if you are having performance issues, like if you're trying to animate hundreds of items, or doing some kind of special effect/image processing.

     

    2 minutes ago, ladlon said:

    but then found out that GSAP won't be able to help me with the random rotation aspect of it. 

     

    It will. You're still having a disconnect between gsap and canvas.

     

    9 minutes ago, ladlon said:

    So, then I pursued the Canvas (non-GSAP) method of doing rotations, but then found out that (apparently) you can only rotate the entire canvas

     

    You're getting bad information from somewhere. Rotation (transforms) is an integral part of canvas. 

     

    image.thumb.png.2b9ff8e217a539b81ef3f11e44a82ed5.png

     

     

     

    • Like 3
  4. 25 minutes ago, OSUblake said:

    This is canvas related code. The code inside the ticker function is going to be unique for almost every animation. 

    
    gsap.ticker.add(function() {  
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      ctx.fillRect(sub.x, sub.y, 100, 100);
    });

     

     

    To further illustrate how this is canvas related code. You don't need to use gsap's ticker. You can do the rAF calls yourself, and it will work the same, although it's recommended to use gsap's ticker.

     

    requestAnimationFrame(draw);
    
    function draw() {  
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      ctx.fillRect(sub.x, sub.y, 100, 100);
      requestAnimationFrame(draw);
    }

     

    • Like 1
  5. My post is about how you keep asking general JavaScript and canvas questions. 

     

    This is gsap related code.

    gsap.to(obj, {
      x: 100
    })

     

    This is canvas related code. The code inside the ticker function is going to be unique for almost every animation. 

    gsap.ticker.add(function() {  
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      ctx.fillRect(sub.x, sub.y, 100, 100);
    });


    I'm willing to help you out, but you have to meet me halfway. Look at everything in this thread. It literally has the answers for you on how to do rotation and other transforms.

    https://greensock.com/forums/topic/16501-how-can-i-improve-this-gsap-particle-animation-code/?tab=comments#comment-73821

     

    So does the demo I posted above. If you need help understanding my code, just ask which part you don't understand. Take it one step at time.

     

     

     

    • Like 3
  6. 59 minutes ago, ladlon said:

    So, does that mean GSAP cannot be used to rotate an item on Canvas?

     

    I've gone over this before. GSAP is not animating canvas. GSAP is animating/updating an object. You take the values of that object and apply to your canvas via draw commands. Canvas draw commands have nothing to do with gsap. Your ticker/draw method should not have anything related to gsap in it. Just vanilla JavaScript.

     

    I've already linked to this. Lots of canvas tips.

     

     

     

    • Like 1
  7. Just now, PointC said:

    ahh... good to know. I just had that happen the other day with that little dog image I use in all my Pixi tests.

     

    Yeah, I think that problem only happens when you view the asset and then try to use it with canvas. It will be cached with the wrong headers.

     

     

     

    • Like 1
    • Thanks 1
  8. 1 hour ago, benoit said:

    Really easy to use PixiJS with TL, but do you know if I can use ParticleContainer with more image (png/svg/…) or I just need to create another ParticleContainer ?

     

    If you need more than 1 image, you would need to use a sprite sheet so there is only 1 baseTexture.

     

    22 minutes ago, PointC said:

    If you're asking why your sprites aren't showing, you have a cross-origin problem.

     

     

    Sometimes codepen sends the wrong headers. Just need to clear the cache by adding something like ?v=1 to the end of the image url.

     

    • Like 5
  9. 10 minutes ago, MindGamer said:

    It seems that an animated DOM element is an "unfinished layout" from Google's perspective.

     

    I don't see how animations would affect that unless you're animating properties that affect layout, like width, height, top, left, etc.

     

     

     

  10. 21 minutes ago, achtzigundsieben said:

    Hope this (smooth scroll without any Scrollbars) is possible with ScrollTrigger?!

     

    Nope. Not unless you hide them. ScrollTrigger requires a scrolling container. That site you linked is fake scrolling.
     

     

     

    • Like 2
×
×
  • Create New...