Comments (3)
I tried lifting it out like so (partial code snippet)
export default function Renderer() {
// Redux store
const background = useSelector((state) => state.world.background);
const images = useSelector((state) => state.images.loadedImages);
const unloadedImages = useSelector((state) => state.images.unloadedImages);
const editorMode = useSelector((state) => state.client.editorMode);
const {mapScale, windowHeight, windowWidth, panX, panY} = useSelector((state) => state.client);
const dispatch = useDispatch();
// get user setttings fil;
const userSettings = require('../assets/world/settings.json');
// state variables
const EDITOR_GRID = {
// editor grid size
// TODO: move to worldSlice
x: userSettings.gridColumns || 56,
y: userSettings.gridRows || 36,
tilesize: userSettings.tileSize || 6,
// editor bounds
left: -1,
right: -1,
top: -1,
bottom: -1,
}
return (
<ReactP5Wrapper sketch={sketch} background={background}
editorMode={editorMode} mapScale={mapScale} windowHeight={windowHeight} windowWidth={windowWidth} panX={panX} panY={panY}
EDITOR_GRID={EDITOR_GRID} images={images} unloadedImages={unloadedImages} dispatch={dispatch}
/>
);
}
// The P5.js sketch
const sketch = (p5) => {
// state variables
let EDITOR_GRID = {
// editor grid size
// TODO: move to worldSlice
x: 56,
y: 36,
tilesize: 6,
// editor bounds
left: -1,
right: -1,
top: -1,
bottom: -1,
}
let mapScale = 0;
let windowHeight = 0;
let windowWidth = 0;
let panX = p5.panX;
let panY = p5.panY;
let background = [];
let images = [];
let unloadedImages = [];
let editorMode = p5.editorMode;
let dispatch = ()=>{};
let unloadedImagesCooldown = -1;
p5.updateWithProps = (newProps) => {
EDITOR_GRID = newProps.EDITOR_GRID;
mapScale = newProps.mapScale;
windowHeight = newProps.windowHeight;
windowWidth = newProps.windowWidth;
panX = newProps.panX;
panY = newProps.panY;
background = newProps.background;
images = newProps.images;
unloadedImages = newProps.unloadedImages;
editorMode = newProps.editorMode;
dispatch = newProps.dispatch;
}
....
rest of functions for drawing and updating
...
}
however either still seems to reupdate or freezes (possibly due to recursive calls)
from react.
Nevermind, did do it!! Found an issue that storing p5js image objects into arrays in global contexts (redux or react createContext) will cause the app to freeze upon resizing the window. Had to make the p5.load'd images now stored in the same file as the sketch and it seems fine
from react.
Closed as the issue is not a library problem and is now resolved.
from react.
Related Issues (20)
- Could not find a declaration file but the code works HOT 10
- Duplicate canvas when running in vite dev HOT 5
- TypeError: p5.loadSound is not a function HOT 4
- P5-wrapper size HOT 5
- Latest commits not in the npm registry HOT 5
- Issue building with Vite 5 HOT 16
- npm ERR! Usage Error: This project is configured to use npm HOT 2
- windowResized() not firing HOT 4
- Error in nextjs HOT 7
- Change p5 dependency version to minimum 1.4.1 HOT 9
- Examples directory doesn't exist, link broken on README HOT 3
- Module parse failed: Identifier 'XX' has already been declared (7762:41) HOT 3
- Is this package supported in React Native? HOT 1
- How to access custom props using abstracted updateWithProps
- Custom updaters as props for use in abstracted methods
- Missing typings for `ReactP5WrapperGuard` in 5.0.0-rc.0 HOT 2
- npm package for version 4.4.1 is empty HOT 3
- It creates new canvas once state is changed HOT 3
- How can I use @P5-wrapper/react in react native HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.