How to add a new background?


#1

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?


#2

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


#3

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


#4

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


#5

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


#6

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


#7

I will try again just in case.


#8

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).


#9

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.


#10

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.


#11

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.


#12

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.


#13

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.


#14

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


#15

What should I search for?


#16

try “black_candle”


#17

I found:

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

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


#18

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


#19

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


#20

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