Hi everyone!
I’m just beginning with Cocos Creator and I struggle to understand the engine.
I’d like to create a very basic game with no physics (as opposed to the documentation first project tutorial) to start getting the hang of things. So I want to make a very basic clicker game.
I’ll try to build it with your help. I’ll be describing my process in very precise details in order to help others understand the engine as well.
Here is what I did so far:
- First, I created an empty project from the dashboard.
- I wanted to change the game resolution of the project so I selected the
Canvas
node in theNode Tree
panel to change theDesign Resolution
properties to 320x180 of theCanvas
component in theProperties
panel. It seems that theSize
properties of theNode
is locked and I don’t know if theDesign Resolution
properties are the good way of changing the game resolution. Am I doing it right or is there another way to control that? - Next, I added an image file 32x32 (png format) inside the assets folder.
- Since I wanted a pixel art style, I selected the image asset in the
Assets
panel to show its properties in theProperty
panel. I changed theFilter Mode
property toPoint
. - I dragged the image asset from the
Assets
panel inside the scene editor to create aNode
with aSprite
component assigned to that image. - I wanted the sprite to appear at a random position inside the canvas. I guessed I had to create a script asset and then attach it as a component to the sprite node. Then I would use the
start
method to set the position of the sprite at the time of its creation with some random function.
So I created a JavaScript script asset and I changed the start
method as such:
start () {
this.node.x = Math.floor(Math.random() * 320);
this.node.y = Math.floor(Math.random() * 180);
}
After selecting the sprite node and adding the script as a new component to it with the Add Component
button and choosing Custom Component -> my_script_name
I clicked the triangle Play
button multiple times to see if the image would change its position each time. It seemed to work properly. However, as you can see, I don’t know how to get by code the canvas resolution So this is my first issue.
How can I get the canvas resolution by code?