How do I keep an object inside the project

Fill this out this info to make it easier for the community to help you! If you don’t fill out this information, your post may be deleted or removed.

What Wick Editor Version are you using?
1.19.3

Describe the Problem
how do I keep an object inside the project area regardless of size. I’m making a vcam move and change size and want to make it stay inside the project area

What have you tried so far?
I haven’t really tried anything because IDK how to go about this (I haven’t used wick in a little while and I’m just getting back in)

Do you have a Wick Editor File that we can see? Optional*
My Project10-23-2024_11-22-05.wick

Make a layer for a rectangle with no fill and a wide enough border that is as long and wide as the project itself. lock this layer and try to fit stuff into it.
Since Wick has no guide layers, once you’re done, you’ll have to manually remove it.

I took a look at your project, and even though it looks normal in the editor… it looks terribly zoomed in inside the actual HTML. Like— I can definitely see what you mean

If you go to the built-in assets you might see “BETA” under the vcam. It’s obviously the problem here… if you look at the zoom code for the vcam, it doesn’t take into account the window size. If you’re to resize your window with the vcam, you’ll see things resize in crazyyyy ways!

But worry not, for I have fixed the beta version of the vcam by rewriting the code to take into account the window’s width and height, and it took a lotta weird math and trial and error to make… so if we get an update for Wick Editor I do hope we replace the built-in vcam’s code with my own. Here’s my genius code:


^ I slightly adjusted the code to work with your vcam’s black borders.

If you’d like another version of my vcam though with possibly something like a screenshot function or what not— you can look for my latest vcam version, or for a simpler version to test and use, the first version works well for that:

Now here’s your project with my vcam’s zoom code:
My Project10-23-2024_20-39-32.wick (22.3 KB)

You should be able to notice the difference in the HTML version.

Compared to how it looked before:

Here’s how it looks now:

If you want to hide the black borders also, you can just change this line in the vcam:

this.project.renderBlackBars = true;

to set it to false rather than true, or if that breaks the project for some reason, just change the vcam’s opacity to zero.

I hope this helps, do lemme know if you still got any questions though :+1:

well I wasn’t really asking about it being too small in html, even though it does help to have a fix, I was asking how to keep to vcam from moving out of the canvas.
this is really simple but just to show you

yes
Screenshot 2024-10-23 7.24.50 PM

no
Screenshot 2024-10-23 7.24.42 PM

btw the newer versions are here silly fighting game

Ah I see! Well, the vcam thing was gonna be an issue when you wanted to publish the game at the end so hopefully it’ll still be useful.

As for how to make sure that the vcam doesn’t leave the screen—
I’m going to draw two rectangles. Imagine that the gray rectangle is the project size (background, the “canvas”), and that the red one is the vcam.

Now, you don’t want the vcam to leave the screen. So, this here is the lowest x value you want the vcam to reach:


^ You don’t want the vcam to go any more to the left of this, or else it’ll leave the screen

Now, notice that the x value at the left side of the project is 0. Also, look at the width of the vcam, and it’s x value.

Now, you might look at this and notice “hmmm… the x value of the vcam is equal to half the width…”
And it’s exactly that!
Since x is zero on the left side, if you add to that zero half the width of the vcam, you will get the lowest x value that you want the vcam to be while staying inside of the project!!

Now, let’s find the highest x value that the vcam can be while still being inside of the project…
Let’s also imagine this scenario… here’s how the vcam would look like if it was at the highest x value it could be while still being inside of the project.

Now let’s look at the x value at the right side, which would be the project’s width (project.width), and the x value of the vcam, and it’s width again.

Notice again, the distance from the vcam’s x value to the right side of the project is half of the vcam’s width. In other words, if you add half of the vcam’s width to it’s x value, you would get the project’s width. To put that into an equation, vcam.x + vcam.width/2 = project.width
Of course though we need to find the x value of the vcam, so you can simply solve by subtracting half the vcam’s width from the project’s width.

vcam.x = project.width - vcam.width/2;

And NOW, we have the lowest x value we want the vcam to be at: vcam.width/2
And the highest x value: project.width - vcam.width/2

You can do if statement to see if the vcam is over or under these values if you want, OR you can use another method that I prefer— say if you don’t want the vcam to go lower than the lowest value, then you can do this:

vcam.x = Math.max(vcam.width/2 , vcam.x);

^ The Math.max function will pick the highest value. In other words, if vcam.x is less than vcam.width/2, then it’ll pick vcam.width/2.

Similary, to stop the vcam from going over the highest x value, you can do

vcam.x = Math.min(project.width - vcam.width/2, vcam.x);

You can combine these two lines to stop the vcam from going higher than the highest value and lower than the lowest value like this:

vcam.x = Math.min(project.width - vcam.width/2, Math.max(vcam.width/2 , vcam.x) );

^ This might look a bit more complicated, but that’s why I tried to explain it in smaller steps and I think it’s kinda a cool way to combine multiple if statements into one line. Do let me know if you don’t understand anything though.

Also, you can probably replace all the “x” with “y” and “width” with “height” to deal with the y value of the vcam as well.

vcam.y = Math.min(project.height - vcam.height/2, Math.max(vcam.height/2 , vcam.y) );

Overall, the code should be something like this

vcam.x = Math.min(project.width - vcam.width/2, Math.max(vcam.width/2 , vcam.x) );
vcam.y = Math.min(project.height - vcam.height/2, Math.max(vcam.height/2 , vcam.y) );

so I tried adding it to the vcam in the game (the one that changes size and moves) and it didn’t seem to do anything. it even seemed to break it.
the game in question
My Project10-25-2024_10-40-34.wick (72.4 KB)
the vcam I want the code in is in the second frame

what did I do wrong here?