Issues with CreateJS chained animations failing to reach their intended target positions

Currently, I am tackling a project that involves using Three.js and CreateJS. However, I have encountered an issue with the animations when trying to move the same object multiple times. The initial animation fails to reach the target position, causing subsequent animations not to initiate.

Below is the JavaScript code from one of my attempts:


import * as THREE from './libs/three.module.js'

let box, canvas, renderer, scene, camera;

function init(){
    setUpCamera();
    setUpScene();
    animate();
}
window.addEventListener('load', init);

function setUpCamera() {
    canvas = document.querySelector('.webgl')
    camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100)
    camera.position.set(0, 10, 15) 
    camera.rotation.x = (-40)*  Math.PI / 180

    renderer = new THREE.WebGLRenderer({
        canvas: canvas
    })

}

function setUpScene() {
    scene = new THREE.Scene();
    scene.background = new THREE.Color(0xbfe3dd);
    scene.add(camera);
    loadBox();
}

function loadBox(){
    let boxGeometry = new THREE.BoxGeometry(5, 5, 5);
    let boxMaterial = new THREE.MeshStandardMaterial( { color: 0x96f2af} );
    box = new THREE.Mesh( boxGeometry, boxMaterial);
    scene.add(box);
}

//Here is the problematic animation
//--------------------------------------------------
function animateBox(){
    console.log("box x position = " + box.position.x);
    createjs.Tween.get(box.position)
        .to({ x: 10 }, 300, createjs.Ease.linear) 
        .to({ x: -10 }, 300, createjs.Ease.linear); 
}
//--------------------------------------------------

function animate(){
    animateBox();
    renderer.render(scene, camera);
    requestAnimationFrame(animate);
}

The following screenshot illustrates the console output indicating that the target position is never reached: https://i.sstatic.net/PnbHg.jpg

Answer №1

You appear to be generating a fresh tween with each frame. Keep in mind that tweens have their own requestAnimationFrame, so it's best to initiate the tween only once instead of every frame.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps for disabling script debugger within Visual Studio 2013

How do I disable script debugging in Visual Studio 2013? I have already disabled script JIT debugging under Tools>Options>Debugging>JIT, and have turned off script debugging in Internet Explorer as well. Despite setting the error option to 'b ...

Error: Trying to access the 'map' property of a null value, Using ReactJS with Axios

I'm currently developing a search bar feature where the user can input their query, hit the search button, and the request is stored in search. This request is then sent via Axios and the results are displayed at the end. Everything seems to be workin ...

How to send props from a Vue.js component tag in an HTML file

I'm facing an issue with passing props from the HTML to the JavaScript code and then down to a Vue component. Here's a snippet of my index.html file: <div id="js-group-discounts"> <div class="form-group required"> <datepick ...

Updating parameters in Node.js with mongoose

script.js var mongoose = require('mongoose'); var Schema = mongoose.Schema; var scriptSchema = new Schema({ status: {type: String, default: 'INCOMPLETE'}, code: String, createdDate: {type: Date, default: Date.now}, user: {t ...

Obtain a string value from a JavaScript object

My dilemma involves a specific Javascript object. { A: 1, B: 2, C: 2, D: 1, E: 1, F: 4, G: 6, H: 2 }, The goal is to extract a four-letter string based on the key with the highest value, but there are limitations. The stri ...

Type property is necessary for all actions to be identified

My issue seems to be related to the error message "Actions must have a type property". It appears that the problem lies with my RegisterSuccess action, but after searching on SO, I discovered that it could be due to how I am invoking it. I've tried so ...

When employing useNavigation, the URL is updated but the component does not render or appear on the

Check out this code snippet: https://codesandbox.io/p/sandbox/hardcore-lake-mptzw3 App.jsx: import ContextProvider from "./provider/contextProvider"; import Routes from "./routes"; function App() { console.log("Inside App" ...

How can I convert an SVG vector file into shapes for Three.js?

I'm looking to showcase a 2D vector map on a three.js webgl canvas using a wireframe material. The original map is in dwg format and needs to be converted to svg. However, I haven't been able to find any SVG importers for three.js. Is there a s ...

How can I achieve independent zooming effects on two PerspectiveCameras with their respective objects in a single scene?

On either side of the window, I have placed two objects. https://i.sstatic.net/CBLw6.png The goal is to enable individual zoom functionality for each object upon hovering over them. var itsLeftControls, itsRightControls; itsRightControls = new THREE.T ...

There seems to be a problem with animating correctly in React when using React Three Fiber and Three.js

I imported a GLTF model from Sketchfab () into my React app. The model loads fine, but the animation isn't playing as expected. I've tried different methods, but the animation seems to reset and start over instead of playing continuously. Any sug ...

What is the best way to apply attributes to all titles throughout a webpage?

My goal is to locate all elements on the page that have a title attribute and add a new attribute to each of them. For example: <div title='something 1'></div> <p>Test<div title='something 2'></div></p ...

Ways to simulate a variable imported in the module being tested without it being a function parameter can be achieved by using describe.each and changing the mock value for each test

I have a requirement to test a function within my TypeScript module. module-to-test.ts import { config } from './app-config'; export const isSomethingWhatINeedSelector = createSelector( firstDependencySelector, secondDependencySelector ...

JSP page displaying a table with a text input field named "code" enclosed within <TD> tags

Recently, I designed a JSP page that features a table with two columns: Code and Description. The table data is an input type of "text" with the name attribute set to "code". The main functionality I need to implement is the automatic generation of the d ...

Unload pre-loaded JavaScript documents

Two javascript files are included in a popup (simple div) created using ajax. <script type="text/javascript" src="<?php echo JS ?>pm.js"></script> <script type="text/javascript" src="<?php echo JS ?>chat.js"></script> ...

What is the reason behind having to refresh my ReactJS page despite it being built with ReactJS?

I have developed a task management application where users can input notes that should automatically update the list below. However, I am facing an issue where the main home page does not display the updated todos from the database unless I manually refres ...

I'm new to Angular, so could you please explain this to me? I'm trying to understand the concept of `private todoItems: TodoItem[] = []`. I know `TodoItem` is an array that

//This pertains to the todoList class// The property name is todoItems, which is an array of TodoItem objects fetched from the TodoItem file. I am unable to make it private using "private todoItems: TodoItem[] = []," is this because of Dependency Injectio ...

When attempting to call a class in Node.js with Express, the return value is coming back

I am relatively new to working with Node.js and the Express framework. I am attempting to pass a value to a JavaScript class in order to process a query and make a call to the database, expecting to receive a result array. Here is the code snippet I am cur ...

The integration between React.js, Node.js, and Express.js is facing issues with the socket.io functionality

I am currently working on integrating socket.io with React.js, running the socket.io on a backend server using Express.js. One issue I am facing is that when an order is placed on the homepage, it should be displayed in real-time on the Orders page in Rea ...

Creating dynamic styles with Material-UI's useStyles

Attempting to implement the same logic using material-ui's useStyle feature <div className={'container ' + (state.unlocked ? 'containerUnlocked' : '')}> I thought it might look like this: <div className={`${clas ...

Error: Attempted to update user profile with an invalid function in Firebase

After creating an Avatar Chooser, I am encountering an error when selecting an image. Instead of displaying the selected image in the avatar, the error message is being displayed. How can I resolve this and ensure that the image appears in the Avatar Icon ...