JeremyBenson11's Recent Forum Activity

  • According to the manual off screen objects aren't still rendered. You could place anything off screen that you don't want rendered, then when it's time to see them place them back on screen. Read the article below to double check. Also if you have lag issues elsewhere the entire first section, in the overview, is about efficiency, proper image use, and stuff like that. Hope this helps.

    https://www.scirra.com/manual/134/performance-tips

  • Call to Action

    This is something that doesn't seem to be around a lot, unless people ask for help. I thought it might be interesting to start a math resource thread. This is where we can help each other learn some great math ideas to help in our games. If people help support the thread by adding their own math knowledge I would learn, and others as well. We should keep the math relevant to Construct 2, and share snippets that would actually help people develop better games.

    I just want to add the premise that the math below was not created by me. You can thank Archipetes, lol, just joking. I got help from here on the Scirra forums to gamedev, but it's good stuff, and should help people, so I'm sharing my findings.

    Some ideas of things people could use in this thread:

    1) The simplest way to move an object in a circle.

    2) How to move an object along an arc.

    3) How to move an object at an arc to 90 degree position (Like would be needed for a circular menu.)

    If someone would add those I would gladly test them, save them for my own efforts, and post them here in the first topic. Also feel free to add any other math bits that would help us here in the forums.

    Note - correct anything below, and I'll test, and update.

    Lerp With Delta Time

    Thanks to a blog post by Ashley, the current C.E.O of Scirra, we learn to use lerp with delta time. The method below is how it works to a 't'. The numbers seem to be pretty precise, so I'll explain below. For an explanation beyond my grasp read his post.

    a = starting point.

    b = destination.

    lerp(a, b, 1 - f ^ dt)

    The lerp function will ease from point a to b. F is a float between 0.1 and 0.9 which will increase or decrease the speed. The lower the number the faster the object will move.

    https://www.scirra.com/blog/ashley/17/u ... delta-time

    Note - A good substitute for lerp is lunarray's plugin: LiteTween. It's great if you don't quite like the behavior of a regular lerp. There's a bit extra with it too, and quite easy to learn.

    Any Point, Any Angle, Any Distance Away

    x = Sprite.X + d * cos(a)

    y = Sprite.Y + d * sin(a)

    The method above will set x and y any number of pixels set by d(distance) in any direction set by the angle. So lerp the following: Sprite.X + 100 * cos(90), Sprite.Y + d * sin(90) will move the sprite 100px in the 90 degrees direction.

    Find an X,Y Within Range

    X = sin(random(0, 360)) * random(1, 100)

    y = cos(random(0,360))) * random(1, 100)

    The following methods will pick a point roughly 1 - 100px away in a random direction. Basically a location within a 100px area. This needs to be calibrated to consider the offset of the sprites size, as the center is usually the starting point, unless specified elsewhere during the sprite editing process.

    Find Point Between Sprites

    Sprite 1 is traveling halfway to sprite 2.

    Adjust fract, or fraction, to change distance.

    fract = 0.5

    Sprite1.x = Sprite2.x + frac * (Sprite1.x - Sprite2.x)

    Sprite1.y = Sprite2.y + frac * (Sprite1.y - Sprite2.y)

    Example:

    Sprite1.x = Sprite2.x + 0.5* (Sprite1.x - Sprite2.x)

    Sprite1.y = Sprite2.y + 0.5 * (Sprite1.y - Sprite2.y)

    Above will move sprite1 halfway of the way towards sprite2.

    Note - The lower the decimal the closer the sprite will move.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You might want to consider using path finding to. The problem you're going to face with lerping sprites around is working around collision objects like walls... if you use the lerp method, and click outside a building, your sprite isn't going to care if it's going through a wall or not... If you use path finding instead it may be a bit easier, and you can use the same method... set the walls as obstacles, and the player should find a way through there, through a door, but not a closed one... You can just stop his path walk if he bumps into something that might be better for you..

    What you would do is add path-finding behavior to your character. On click find path... then next event.. on path found.. start following path... Not sure if that needs to be every tick or not.. Just test it without first... You can set acceleration based on distance.. new event, the cogwheel compare two values... the first value will be distance(player.mouseX, player.mouseY, player.X, player.Y) < 10 then set acceleration slower... if 20 or whatever, set acceleration higher...

    mouseX and mouseY are instance variables like before attached to your player, you attach them yourself as a number..

    On start of layout event... set all your obstacles in path finding..

    A crucial step is to set cell size. You do this in the layout window after clicking your path-finding sprite. To the left.. find cell size and set it to roughly the size of your box the sprite is in.. should be something like 32, 64... not sure about rectangles.. but I find having the cell size as close to the box size, or a tiny pinch smaller works best..

  • The problem is if you have animations you'll need to find a way to know which direction the sprite is moving in to work accordingly. One issue is I'm not sure how you want to let the player move. This method will let the player move almost anywhere, kind of like gliding there. You'll need to set that with animations if you're okay with that.. But if it's like the old old Ultima games, you would need to do something else, like only allowing four direction move..

    What I put above might not even be what you're looking for

  • Just a quick question. Why would I use this over local storage, which does the same thing in ini format?

  • I'm not sure that construct gives you any way to work with collision data at all. As far as I've seen it only allows you to collect the fact that a collision has occurred. A less accurate method would be to collect the x, y position of the object you are colliding with and spawn the object here...

    A more accurate way would be to create your own buffers, or sensors. Little objects so far away from the object like, tiny clear squares, and then spawn the object at the location of the square the hits.. This would be tricky and require some overhead, because you're going to have to turn off the sensors as soon as there's a collision, and then turn them back on when they are overlapping nothing but the ball... or set them some pixels away from the ball..

    Honestly, neither seem really professional. I'd like to see the proper answer for this. I've yet to see anyone talk specifics on collecting collision data...

  • Moving to a mouse click is easy. You can create instance variables. mouseX, and mouseY on the player. When the mouse is clicked you can set those values to Mouse.X, and Mouse.Y. Then you can create an event that will move the player to that position.

    Make sure the mouse object is in the layout..

    If you don't mind if they lerp there then:

    set position event

    in the x box

    lerp(player.X, player.mouseX, 1 - 0.5 ^ dt)

    in the y box

    lerp(player.Y, player.mouseY, 1 - 0.5 ^ dt)

    The mouse icon would be pretty easy too.

    for the event you would do the cog wheel compare two values distance(player.X, player.Y, mouse.X, mouse.Y) <= x

    set cursor to this image.. then you do another event for the second image.

    X in this instance is replaced by the distance in pixels.

    If you want the player to move fast when clicking far away... you can do an event.. if distance from

    player.mouseX, player.mouseY > x

    then lerp(player.X, player.mouseX, 1 - 0.3 ^ dt) -- see here 0.5 became 0.3, which is a quicker speed.

    Do the same for setting player Y...

    that number can't be greater than of equal to 1... so 0.1 - 0.9 the lower the number the faster the lerp... if you find lerp isn't working for you there is LiteTween, which is a custom plugin you can get here:

    It's like lerp, but a little more to it..

    Please forgive if the math is a little off, but I think this will work, and a good starting point to experiment with in the least..

  • wow, if that sends a message to Google, or some other place, I have no idea... Does that connect to some kind of API, or do you just need to get permission? If you just need permission you wouldn't need this. All you would have to do is have your first layout be the policy. If they accept send their username and message to the database saying they accepted the policy, then show them the game... if they click no... show them the game, without the ads, or without what they say you can't show without permission. If nothing send them to a layout that says, "sorry, can't play without permission." Then an ok button.. have the ok button go back to the permission collection layout.

    It really depends on if that code above communicates through an API to an external site...

  • I'm gonna be honest, but in-case those who have helped me are reading, this doesn't apply to those who have responded to my posts... Those guys are cool, and helped solve every problem... but this forum is, or at least my first impression after a couple of days posting, was that this forum is NOT the most helpful on the web. Trust me, there are other forums that will get 8 posts a thread, and people are eager to help. This is not that kind of place. I had several threads sink to the bottom, before I ever got a reply. I seen people with four bumps through a couple of days... but... I did eventually start getting replies... also, you could help others while you're waiting. People will notice that you're helping, even if it's a small amount... you're in general topic right now, make some friends by talking about your favorite game, or the weather... if you know something, add it as a tutorial... People will notice you and help you... but.. if you're lazy... like Prominent says, this is just the way the forum works here... some get answered, some don't...

  • But if I use web storage, this NW.js right? Wouldn't I need to set up my own method of separating the json strings? There would be some kind of delimiter? Then how do I read in the string, and use the delimiter to break them back and put them in my objects? That's kind of what I'm wondering. I don't really understand how to do it through Construct. It's not really the same as using other languages, with knowledge of how the events flow..

    Would it be easier to serialize by json strings into keys, and use local storage? What method works best for broad range of devices?

    Thanks for your reply,

    Jeremy.

  • Cool, thanks to both I finally have all the math needed for basic movement.

    Discovered how to move an object a number of px in any direction..

    How to move object up to a certain random number of px from itself..

    Now I just need to figure out custom movements, like following an arc, or what have you.. Have no idea where to start with that..

  • No problem, glad it helped

JeremyBenson11's avatar

JeremyBenson11

Member since 24 Aug, 2015

None one is following JeremyBenson11 yet!

Trophy Case

  • 9-Year Club
  • Email Verified

Progress

10/44
How to earn trophies