How to add a new background?

In the 2D Platformer Creation Kit I have been trying to change the background. In the background.script I have added a new else if section for the new background image:

elseif self.type == hash( "mybackground" ) then
	msg.post( "#sprite",  "play_animation", { id = hash("mybackground") } )
	go.set(   "#sprite",  "scale", vmath.vector3( .666 ) );
	msg.post( "#sprite1", "disable" )
	msg.post( "#sprite2", "disable" )
	msg.post( "#sprite3", "disable" )

In … / framework / sprites I have added a new mybackground.png.

In backgrounds / background.go I have created sprite4 component. In the Properties panel, inside the Default Animation that image does not appear.

What could it be I have misunderstood?

Have you added the “mybackground.png” to the atlas file that the sprite uses?

Yeah, adding images to atlas first is still a new idea for me to get used to. That fixed it.

1 Like

The HTML version is now very slow. Is the image too big or is there a problem with the code?

Do you get the same slowdown if you bundle to HTML5 and check the “release” checkbox?

I’m already using [x] Release, as it sounds “final”.

I will try again just in case.

I would also suggest to compare performance between Firefox and Chrome. Chrome is known to be a bit slower when running non-release Defold games (due to debug version will validate WebGL calls to catch errors, which is notoriously slow in Chrome).

1 Like

Reloading the web page helped. Google Chrome possibly had an old cache as I’m using the same address all the time. Also, I saw an error when uploading the files to my school’s server, so maybe some files got corrupted, etc.

1 Like

I added another background, and now all the levels have the same black_candle background. I can’t find my error, but there must be something I’m missing.

I removed the image from the atlas and from the code, and now I get:

ERROR:GAMESYS: Default animation ‘black_candle’ not found
WARNING:RESOURCE: Unable to create resource: build/default/platformer_creation_kit/building_blocks/gameobjects/backgrounds/background_generated_5.spritec
WARNING:RESOURCE: Unable to create resource: build/default/platformer_creation_kit/building_blocks/gameobjects/backgrounds/background.goc
ERROR:GAMEOBJECT: Could not instantiate game object from prototype /platformer_creation_kit/building_blocks/gameobjects/backgrounds/background.goc.
WARNING:RESOURCE: Unable to create resource: build/default/platformer_creation_kit/LevelFiles/MyLevel.collectionc
ERROR:GAMESYS: The collection /platformer_creation_kit/LevelFiles/MyLevel.collectionc could not be loaded.

Yes, each image you add to an atlas create a new animation, remove the image and the animation can’t be found anymore. You are referencing the animation somewhere.

I used Undo to not delete image from atlas and not remove the image from code, so I’m back to the problem where I have the same black_candle on all levels. Just can’t find my mistake.

There is a pretty good search function in the editor. Have you tried using it?

1 Like

What should I search for?

try “black_candle”

1 Like

I found:

120: “default_animation”: “black_candle”\n"

When I double click that I can not see the original file that has that line.

I think the problem is that I did not disable other sprites.

It will open the file that has a sprite that has “black_candle” as default animation.

1 Like

Now the preview in Defold shows incorrect black_candle, but in the game it is the correct background.