Comments (11)
Hi Peter,
Actually even without using dirty rectangle, someone else doing the same thing (switching between two characters) reported me the same behavior. So there is definitely something wrong with my algorithm, I'll review my code quietly and let you know ASAP. Thank you !
from melonjs.
I think I've got it working now, though I'm not sure why it works. When I get chance I'll post the code I used in a gist (my code, I didn't have to change the melonJS source at all)
from melonjs.
Hmm interesting... Did u use me.game.repaint() ?
i'm really curious to see how you've done it :):):)
On 4 oct. 2011, at 16:35, Peter Hull [email protected] wrote:
I think I've got it working now, though I'm not sure why it works. When I get chance I'll post the code I used in a gist (my code, I didn't have to change the melonJS source at all)
Reply to this email directly or view it on GitHub:
https://github.com/obiot/melonJS/issues/17#issuecomment-2283716
from melonjs.
Unfortunately I haven't fixed it. It works as long as there's an animated object somewhere else on screen - once they're gone it doesn't work any more. I'll do some more checking...
from melonjs.
well actually it makes sense, as the draw manager will only create a dirty rectangle corresponding to your entity if that same entity has been updated (either animation update, or position change). Now since you're only changing the camera focus (on entity), there are no "reason" for the draw manager to redraw the screen area where your entity is, since the same entity did not change.
Now I don't know if the previous explanation and the corresponding algorithm is right, but what you could however is the following thing :
- in each of the entity (that the camera can follow), override the update function (if not yet done)
- update a flag somewhere with the name of the entity that is gaining focus
- from the overriden update, either return the value of the parent update (or the one returned by updateMovement) OR if the flag is equal to the entity name, force the update (and as consequence a draw) by returning true.
let me know how is this working,
Oliver.
from melonjs.
I did something similar: I added a member variable to each entity called forceUpdate
. When switching to an entity, its forceUpdate
is set to true. In the update
function, if forceUpdate
is set I make sure that update
returns true, and then reset forceUpdate
to false.
Unfortunately this doesn't fully solve the problem. I think it's something to do with the visible
property. An object isn't redrawn if is isn't visible according to that property, but if the viewport is changed part way through the update cycle, then the visible property is not necessarily accurate any more.
from melonjs.
hmm... right, you're changing the viewport part way through the update cycle !
So you should try this:
me.game.viewport.follow.defer(myEntity);
Using Defer will "postpone" the execution of the function to when the stack is empty, which means in your case when the update cycle is over. I had exactly the same kind of issue when I was switching level with dirty Rect (the first frame was not correctly refreshed), and this is how I solved it.
You need of course a recent version of melonJS, see this commit :
https://github.com/obiot/melonJS/commit/f3b029ac73c43bb01bf9c3acaea60ad874bf2e05
I think that combined with your forceUpdate code, it should do the trick
from melonjs.
Hi Peter,
Any progress on your side ? Feel free to send me your code ([email protected]) if you want, maybe I can also try on my side to see how to get this working. It will be easier for me to help if I have a proper example.
from melonjs.
Hi,
I've not had much time on it. I tried the defer trick but it didn't
work*. I will send my code, hopefully this evening. You're right, we
won't make progress any other way!
Thanks,
Pete
- Your code
me.game.viewport.follow.defer(myEntity);
didn't seem to work as 'this' wasn't set correctly to the viewport. I
changed it to
(function(p) { me.game.viewport.follow(p); }).defer(MyEntity.pos);
and it is certainly called, but the target entity still doesn't appear
until it moves.
On Fri, Oct 7, 2011 at 10:10 AM, obiot
[email protected]
wrote:
Hi Peter,
Any progress on your side ? Feel free to send me your code ([email protected]) if you want, maybe I can also try on my side to see how to get this working. It will be easier for me to help if I have a proper example.
Reply to this email directly or view it on GitHub:
https://github.com/obiot/melonJS/issues/17#issuecomment-2319391
from melonjs.
And did you try something like this :
(function(p) {
// supposing both your entities have the flag we discussed earlier
p.forceUpdate = true;
// change the camera
me.game.viewport.follow(p.pos, me.game.viewport.AXIS.BOTH);
// force repaint (not sure if it's needed)
me.game.repaint();
}).defer(MyEntity);
FYI, this is working perfectly when not using Dirty Rectangle (does not mean it will work in your case though).
from melonjs.
Corrected & Confirmed as working by Peter.
from melonjs.
Related Issues (20)
- Optimize the `arcTo` function to use `gl.LINES` HOT 1
- Cache or optimize triangulation data used for drawing with fill operation
- `textImage2D` does not accept OffscreenCanvas anymore as a pixel source for texture
- optimize matrix operations using Strassen algorithm ? HOT 5
- compressed textures in WebGL HOT 3
- WebGPU renderer
- TypeScript defenition for loader.preload incorrect HOT 6
- [Feature request] More realistic progress based on bytes for loader and preloader
- Texture is never removed from TextureCache
- TextureCache.length can't be decreased HOT 5
- support using SVG path data when creating a Path2D path HOT 1
- this.body is pointing to Dom type when using Typescript Boilerplate HOT 8
- Animation created from atlas: misaligned hitbox HOT 1
- Some of the Github pages examples are broken HOT 3
- Difficulties with UITextButton HOT 6
- Animation broken on WebGL if TextureAtlas has multiple textures HOT 9
- The result of the flip object vibrates
- Hyperlinks to source code within documentation contain absolute path on obiot's PC HOT 4
- withCredentials does not get set in fetch calls HOT 3
- [documentation] migrate to vitepress-jsdoc
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 melonjs.