Giter Site home page Giter Site logo

Comments (11)

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

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.

 avatar commented on May 11, 2024

Corrected & Confirmed as working by Peter.

from melonjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.