Discussion about this post

User's avatar
Mckenytech's avatar

Whenever I publish it, you could write the docs for it...

Expand full comment
Mckenytech's avatar

React native skia is great... this my render...const Render = () => {

const { SCREEN_HEIGHT, SCREEN_WIDTH ,MAP_OFFSET} = useConstants();

const bg =useImage(require("../../assets/maps/world_1.png"))

const systems = useRegistry((state) => state.systems);

if (!systems[SystemType.RENDER]) {

return null;

}

return (

<Canvas style={{ width: SCREEN_WIDTH, height: SCREEN_HEIGHT }}>

<Image

x={0}

y={MAP_OFFSET}

//transform={[{scale:1.7}]}

width={211 * 16}

height={15 * 16}

image={bg}

/>

{

systems[SystemType.RENDER].entities.map((entity, index) => {

const pos = entity.components.find(

(c) => c.name === CompName.POSITION

) as PositionState;

const area = entity.components.find(

(c) => c.name === CompName.AREA

) as AreaState;

const mass = entity.components.find(

(c) => c.name === CompName.MASS

) as MassState;

const rect = entity.components.find(

(c) => c.name === CompName.RECT

) as RectState;

const Spritey = entity.components.find(

(c) => c.name === CompName.SPRITE

) as SpriteState;

const Color = entity.components.find(

(c) => c.name === CompName.COLOR

) as ColorState;

if (pos) {

//console.log("pos", pos.state.x.value, pos.state.y.value);

const spriteHeight = 50;

const spriteWidth = 50;

let areaOutlineRender = null;

let rectRender = null;

let entityRender = null;

if (Spritey) {

// console.log("Spritey", Spritey.state.sprite);

const sprite = ecs.getState().getSprite(Spritey.state.sprite)

//console.log("sprite", sprite);

entityRender = (

<Image

key={`sprite-${index}`}

x={pos.state.x}

y={pos.state.y}

width={spriteWidth}

height={spriteHeight}

image={sprite}

/>

);

}

if (rect) {

console.log("rect", rect.state.width, rect.state.height);

rectRender = (

<Rect

key={`rect-${index}`}

x={pos.state.x}

y={pos.state.y}

width={rect.state.width}

height={rect.state.height}

color={Color?.state.color}

/>

);

}

if (area) {

areaOutlineRender = (

<Rect

key={`stroke-${index}`}

x={pos.state.x}

y={pos.state.y}

width={area.state.width}

height={area.state.height}

style="stroke"

color="green"

strokeWidth={6}

/>

);

}

return [entityRender, areaOutlineRender, rectRender];

}

return []; // Return an empty array instead of void

})

}

</Canvas>

);

};

export default Render ;

const styles = StyleSheet.create({

container: {

flex: 1,

backgroundColor: "#fff",

alignItems: "center",

justifyContent: "center",

},

});

Expand full comment
11 more comments...

No posts