How do I Use Javascript to Offset Sprite Position Drawing

  • I'd tried Googling this and came up with nothing. Then there'd be the problem of how to reference the variable of a sprite's air height because I want to use this for an easy jumping effect in a top-down view.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Typically javascript is never the solution. Why not just move it with events, it's almost always easier? If it messes up whatever other movement you have then you could make a second object and position that from the first one, and make the first sprite invisible.

    If you really want to use javascript then look at making a behavior with the sdk. There's a section on the manual for it.

  • You can do it with events. I don't have access to C2 at the moment but here's a C3 example file that might help.

    I guess it's something like this you want to do.

    https://www.dropbox.com/s/s9xuhp432is67 ... p.c3p?dl=1

  • I basically just have an event at the very end of my events that moves the object to it's Y position - air height, then at the very start of the code it's told to do the opposite so its collision detection and everything is still at base air height, but the sprite is drawn at its air height to pull off fake 3D. I just was thinking it might be more efficient to do this another way because I need to optimize my game some more, but I guess 0.7% CPU usage on each of those events alone isn't enough to even care about. That's a lot less than I thought it was.

    By the by, is this 64 collisions per tick when nothing is happening good for having 2,273 objects in a layout? Most are static obstacle objects.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)