HI everyone hope you are doing well, So I am totally new to playcanvas so I am stuck in whole lot things as I am not using the online editor but have installed playcanvas by npm.
So my biggest problem right now is that I am trying to make a 2D game with only code of course but I just have not been able to get the sprites render on screen, here is the code I found and was trying to use
var textureAsset = app.assets.find('512x512 v2.png', 'texture');
var texture = textureAsset.resource;
texture.addressU = pc.ADDRESS_CLAMP_TO_EDGE;
texture.addressV = pc.ADDRESS_CLAMP_TO_EDGE;
texture.minFilter = pc.FILTER_NEAREST;
texture.magFilter = pc.FILTER_NEAREST;
var atlas = new pc.TextureAtlas();
atlas.frames = {
"0": {
rect: new pc.Vec4(0, 0, 512, 512),
pivot: new pc.Vec2(0.5, 0.5)
}
};
atlas.texture = texture;
var sprite = new pc.Sprite(app.graphicsDevice, {
atlas: atlas,
frameKeys: '0',
pixelsPerUnit: 100,
renderMode: pc.SPRITE_RENDERMODE_SIMPLE
});
var spriteAsset = new pc.Asset('sprite', 'sprite', { url: '' });
spriteAsset.resource = sprite;
spriteAsset.loaded = true;
app.assets.add(spriteAsset);
var entity = new pc.Entity();
entity.addComponent('sprite', {
type: pc.SPRITETYPE_SIMPLE,
spriteAsset: spriteAsset,
});
entity.addChild(entity);
what i think is that the image is stored in the asset registry but does that work for a react project?? I would really like some help here Thank you.